standup75 standup75 - 1 month ago 15
Git Question

Who deleted my change in git?

Here was my problem for the last 30 minutes: I had a couple of changes that disappeared in one of my files, and I don't know when that happened. And I want to know who did that!

I started looking for the revisions having my files:

git grep <searched_string> $(git rev-list --all) -- <file>


is the path to the file or a wildcard like *.gsp

I got a bunch of revisions, I look at the last one, and try to get it's children (thinking the first child should be the first revision where my changes disappeared)

git rev-list --children <revision_id>


is the 40 chars from the beginning of the last line of the previous command

Getting close! I am looking at the beginning of the output, and take the first child and then run

git log <revision_id_s_first_child> --stat


Then I look at the output and find my file and who did the change!
(it turned out, I was to blame...)

Is there anyway to do that faster (git blame would not show what has been deleted) ?

Answer

git blame has a --reverse option that takes a range of commits and shows you the last commit where a line existed before it was deleted. So, you find a commit you know the lines were there, let's say abcdef01 for example, and to show the last commit before the delete, do:

git blame --reverse abcdef01..HEAD -- <file>