How to blame a deleted file in git?

Git blame helps when investigating why code in a file is a certain way. git gui is even better in that it allows you to step backwards in time to see the context of the file when code was added.

However, git blame <file> and git gui blame <file> do not work after a file has been deleted. An error will appear as:

fatal: cannot stat path 'file': No such file or directory

How does one blame a deleted file?


git blame

git blame works when providing a commit reference that contains the file. Find the most recent one with log:

$ git log -2 --one-line -- example/path/file.txt

 fffffff deleting file.txt
 eeeeeee Last change to file.txt before deleting.

Then blame the parent commit:

$ git blame eeeeeee -- example/path/file.txt

git gui blame

git gui blame won't work this way, however. A work around is to browse the repository at the last commit that contained the file, then from the GUI select the file and launch the blame viewer:

$ git gui blame eeeeeee example/path/file.txt

(Note: Use log -2 and eeeeeee instead of fffffff^ because git gui blame can not handle fffffff^:example/path/file.txt )

链接地址: http://www.djcxy.com/p/22672.html

上一篇: Git仅记录文件的一部分?

下一篇: 如何指责在git中删除的文件?