git blame
git
用法
git blame [-L <start>,<end>] <file>给每一行标出最后改动它的提交;只做格式化的提交会盖住真正的作者,这就是 -w 和 --ignore-rev 的用处。
常用选项
| 选项 | 含义 |
|---|---|
| -L <a>,<b> | only those lines |
| -w | ignore whitespace, so re-indenting stops hiding the author |
| -C | follow code moved in from another file |
| --ignore-rev <rev> | skip a commit, e.g. a bulk reformat |
| -e | show email addresses instead of names |
| -s | drop the author and date columns |
示例
git blame -L 40,60 src/app.tswho last touched lines 40 to 60
git blame -w -C src/app.tslooks past whitespace and moved code
git blame --ignore-rev 9f3c2ab src/app.tsignores the commit that reformatted everything
难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. git blame 是做什么的?
给每一行标出最后改动它的提交;只做格式化的提交会盖住真正的作者,这就是 -w 和 --ignore-rev 的用处。
Q. 怎么写?
git blame [-L <start>,<end>] <file> —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 6 个,完整列表在 man git。这条命令属于git。
相关命令
man 手册: man git-blame