For changes hidden in merge commits
Merge commits automatically have their changes hidden from the Git log output. Both pickaxe and reverse-blame did not find the change. So the line I wanted had been added and later removed and I wanted to find the merge which removed it. The file git log -p -- path/file
history only showed it being added. Here is the best way I found to find it:
git log -p -U9999 -- path/file
Search for the change, then search backwards for "^commit" - the first "^commit" is the commit where the file last had that line. The second "^commit" is after it disappeared. The second commit might be the one that removed it. The -U9999
is meant to show the entire file contents (after each time the file was changed), assuming your files are all max 9999 lines.
Finds any related merges via brute force (diff each possible merge commit with its first parent, run against tons of commits)
git log --merges --pretty=format:"git diff %h^...%h | grep target_text" HEAD ^$(git merge-base A B) | sh -v 2>&1 | less
(I tried restricting the revision filter more, but I ran into problems and don't recommend this. The add/removal changes I was looking for were on different branches which were merged in at different times and A...B did not include when the changes actually got merged into the mainline.)
Show a Git tree with these two commits (and a lot of the complex Git history removed):
git log --graph --oneline A B ^$(git merge-base A B)
(A is the first commit above, B is the second commit above)
Show history of A and history of B minus history of both A and B.
Alternate version (seems to show the path more linearly rather than the regular Git history tree - however I prefer the regular git history tree):
git log --graph --oneline A...B
Three, not two dots - three dots means "r1 r2 --not $(git merge-base --all r1 r2). It is the set of commits that are reachable from either one of r1 (left side) or r2 (right side), but not from both." - source: "man gitrevisions"
git log -S<string> /path/to/file
wants a-c
or-cc
as well to show removals during merge (conflicts) – Disavow-c
and--cc
. @Steen: Correct, thanks for pointing out! Stupid oversight. Wish I could edit the comment. Adding a new one, then deleting mine, then you delete yours is all too cumbersome I guess :) – Disavowgit blame
would have an option to show deleted lines (with perhaps strikethrough or red text) with the revision in which they were deleted. – Kickshaw