blog icon indicating copy to clipboard operation
blog copied to clipboard

Git_7 提交历史(git log)

Open qingquan-li opened this issue 7 years ago • 0 comments

Git 提交历史

查看提交历史

  • git log :默认不用任何参数的话,git log 会按提交时间列出所有的更新,最近的更新排在最上面。会列出每个提交的 SHA-1 校验和、作者的名字和电子邮件地址、提交时间以及提交说明
  • git log -p -<n> :用来显示每次提交的内容差异,也可以加上 -数字 来仅显示最近 n 次 提交。该命令除了显示基本信息之外,还附带了每次 commit 的变化
  • git log --stat :显示每次提交的简略的统计信息。--stat 选项在每次提交的下面列出额所有被修改过的文件、有多少文件被修改了以及被修改过的文件的哪些行被移除或是添加了。 在每次提交的最后还有一个总结
  • git log --pretty=oneline :用 oneline 将每个提交放在一行显示,查看的提交数很大时非常有用。 Pretty 选项还有一些内建的子选项,例如:short,full 和 fuller
  • git log --pretty=format:"要显示的记录格式" : 示例: git log --pretty=format:"%h - %an, %ar : %s" 。具体参考:https://git-scm.com/book/zh/v2/Git-基础-查看提交历史
git log --pretty=format 常用的选项 说明
%H 提交对象(commit)的完整哈希字串
%h 提交对象的简短哈希字串
%T 树对象(tree)的完整哈希字串
%t 树对象的简短哈希字串
%P 父对象(parent)的完整哈希字串
%p 父对象的简短哈希字串
%an 作者(author)的名字
%ae 作者的电子邮件地址
%ad 作者修订日期(可以用 --date= 选项定制格式)
%ar 作者修订日期,按多久以前的方式显示
%cn 提交者(committer)的名字
%ce 提交者的电子邮件地址
%cd 提交日期
%cr 提交日期,按多久以前的方式显示
%s 提交说明

注意:作者 和 提交者 之间究竟有何差别, 其实作者指的是实际作出修改的人,提交者指的是最后将此工作成果提交到仓库的人。


git log 的常用选项 说明
-p 按补丁格式显示每个更新之间的差异
--stat 显示每次更新的文件修改统计信息
--shortstat 只显示 --stat 中最后的行数修改添加移除统计
--name-only 仅在提交信息后显示已修改的文件清单
--name-status 显示新增、修改、删除的文件清单
--abbrev-commit 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符
--relative-date 使用较短的相对时间显示(比如,“2 weeks ago”)
--graph 显示 ASCII 图形表示的分支合并历史
--pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format(后跟指定格式)

限制(提交历史的)输出长度

限制 git log 输出的选项 说明
-(n) 仅显示最近的 n 条提交
--since, --after 仅显示指定时间之后的提交
--until, --before 仅显示指定时间之前的提交
--author 仅显示指定作者相关的提交
--committer 仅显示指定提交者相关的提交
--grep 仅显示含指定关键字的提交
-S 仅显示添加或移除了某个关键字的提交

实例:

  • git log -p -<n> :仅显示最近 n 次提交
  • git log --since=2.weeks :列出所有最近两周内的提交

git log --graph

$ git log --graph --pretty=oneline --abbrev-commit
*   635fb0c (HEAD -> function-state, origin/function-state, origin/dev, dev) Used "state" in components to update data
|\  
| * 3be5622 Used "state" in components to update data
* | bd7eab7 Added comment to explain `this.props`
|/  
* 3aedd83 Use "props" in components
*   da59c9d (origin/master, master) Merge pull request #1 from FatliTalk/dev
|\  
| * 785a523 use Function (Table) Component
| * 28bf37e hard-code table with Class Component
|/  
* 8a758f9 Remove sourceMappingURL=bootstrap.min.css.map from bootstrap.css
* a43bf19 Display "Hello World!" with Bootstrap
:...skipping...
*   635fb0c (HEAD -> function-state, origin/function-state, origin/dev, dev) Used "state" in components to update data
|\  
| * 3be5622 Used "state" in components to update data
* | bd7eab7 Added comment to explain `this.props`
|/  
* 3aedd83 Use "props" in components
*   da59c9d (origin/master, master) Merge pull request #1 from FatliTalk/dev
|\  
| * 785a523 use Function (Table) Component
| * 28bf37e hard-code table with Class Component
|/  
* 8a758f9 Remove sourceMappingURL=bootstrap.min.css.map from bootstrap.css
* a43bf19 Display "Hello World!" with Bootstrap
* b225eb4 Initialize project using Create React App
~
~

qingquan-li avatar Oct 12 '17 09:10 qingquan-li