查看文件中每行代码的最近一次修改人
git blame file_name
git blame <filename>
git blame -L 100,100 <filename>
git blame -L 100,+10 <filename>
查看最近两次变动及其变动点
git log -p -2
显示增改行统计
git log --stat
git log –pretty 选项,可以指定使用完全不同于默认格式的方式展示提交历史
按行展示spi_flash.c的每次提交
git log --pretty=oneline spi_flash.c
展示spi_flash.c的每次提交的作者和提交说明
git short --pretty=oneline spi_flash.c
展示spi_flash.c的作者提交人,日期等其他信息
git full --pretty=oneline spi_flash.c
git fuller --pretty=oneline spi_flash.c
git log –format,可以定制要显示的记录格式,这样的输出便于后期编程提取分析
git log --pretty=format:"%h - %an, %ar : %s"
选项 | 说明 |
---|---|
%H | 提交对象(commit)的完整哈希字串 |
%h | 提交对象的简短哈希字串 |
%T | 树对象(tree)的完整哈希字串 |
%t | 树对象的简短哈希字串 |
%P | 父对象(parent)的完整哈希字串 |
%p | 父对象的简短哈希字串 |
%an | 作者(author)的名字 |
%ae | 作者的电子邮件地址 |
%ad | 作者修订日期(可以用 -date= 选项定制格式) |
%ar | 作者修订日期,按多久以前的方式显示 |
%cn | 提交者(committer)的名字 |
%ce | 提交者的电子邮件地址 |
%cd | 提交日期 |
%cr | 提交日期,按多久以前的方式显示 |
%s | 提交说明 |
作者(author)指的是实际作出修改的人,提交者(committer指的是最后将此工作成果提交到仓库的人。
用 oneline 或 format 时结合 –graph 选项,可以看到开头多出一些 ASCII 字符串表示的简单图形,形象地展示了每个提交所在的分支及其分化衍合情况
选项 | 说明 |
---|---|
-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 | 仅显示指定提交者相关的提交。 |
git log –pretty=”%h - %s” –author=gitster –since=”2008-10-01” –before=”2008-11-01” –no-merges – t
git log --pretty="%h - %s" --author=zhangyuhu --since="2016-10-01" --before="2017-11-01" --no-merges
使用 log 来查看某一行的所有操作
git log -L start,end:file