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) ?
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.
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.
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!
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.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With