Git blame用于查找文件中代码为什么是某种方式。而git gui更好,因为它允许您向后跳转以查看添加代码时文件的上下文。
但是,在文件被删除后,git blame <file>
和git gui blame <file>
将无法使用。将出现错误:
fatal: cannot stat path 'file': No such file or directory
如何归咎于已删除的文件?
Git Blame
命令需要提供包含该文件的提交引用才能运行。使用log
命令查找最近的引用。
$ git log -2 --oneline -- example/path/file.txt
fffffff deleting file.txt
eeeeeee Last change to file.txt before deleting.
那就归咎于父提交:
$ git blame eeeeeee -- example/path/file.txt
git gui blame
命令不能直接使用。一个解决办法是浏览到包含该文件的最后提交的版本,然后从图形化界面中选择该文件并启动 blame 查看器。
$ git gui blame eeeeeee example/path/file.txt
(Note: 使用 log -2
和 eeeeeee
代替 fffffff^
,因为 git gui blame
无法处理 fffffff^:example/path/file.txt
。)
git log -p
,而非git blame
,详情请见:https://dev59.com/SnVC5IYBdhLWcg3wfhKL#278242 - Big McLargeHuge