Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who deleted my change in git?

Tags:

git

revision

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) ?

like image 423
standup75 Avatar asked Aug 31 '11 20:08

standup75


People also ask

How do you check who deleted files in git?

Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.

Does git keep track of deleted files?

It keeps track of all the changes to your files over time. If you ask it to, it can reset any file's contents to match a previous version.

How do I recover a deleted .git file?

Even better, in cases like committing a file deletion and then wanting to revert it, Tower's awesome undo feature lets you get the file back by simply pressing CMD-Z!

How can I see when my git change was last?

If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.


2 Answers

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>
like image 168
Karl Bielefeldt Avatar answered Sep 23 '22 15:09

Karl Bielefeldt


If you know some substring that would be in the line that was removed, then you can use the -G option to git log to find commits that introduced a change that added or removed lines containing that substring. e.g. if you knew that the word "pandemic" was in the line that disappeared, you can do:

git log -Gpandemic -p

(The parameter to -G can be a regular expression.) This option was added rather recently to git - if it doesn't work, try -S instead, which has slightly different semantics, but should have a similar effect.

like image 45
Mark Longair Avatar answered Sep 21 '22 15:09

Mark Longair