Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

How can I 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?

question from:https://stackoverflow.com/questions/37084243/how-can-i-blame-a-deleted-file-in-git

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

git blame

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

$ git log -2 --oneline -- 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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...