tags:

views:

53

answers:

2

say I merged a branch to my master branch. Worked on it for a while, then realized some bug was introduced after the merge.

How can I then see a list of files that were effected in the merge, and then one by one see a diff of them?

A: 

Your best bet is to characterize the bug into a test and then use git bisect to tell you which change introduced the bug. If you don't use automated testing, it'll be harder (won't be as automated), but it will tell you the specific change that introduced the bug.

Assuming people on your project are good at communicating changes that are small (does one thing) and descriptive (describes what that one thing is well), the effort required to figure out exactly what broke stuff is trivial.

Dustin
+1  A: 

git bisect, as suggested in the other answer, is certainly very useful for tracking down which commit introduced a bug, and may well find your problem very fast. It's possible that the merge commit may be the one at fault, however, and in any case perhaps a direct answer to your question might be interesting.

Firstly, you should find the object name (i.e. SHA1 sum) of the merge commit you're interested in, perhaps with git log --graph --pretty=oneline or gitk - let's say that this merge commit's object name begins with d8fa for this example.

In git, commits are defined in terms of a complete snapshot of the tree rather than changes to the tree, and this is as true for merges with two (or more) parents as any other commit. So, perhaps the most obvious question to ask about what was changed by a merge commit is "what changed with respect to each parent of this merge?" You can refer to the first parent as d8fa^1 and the second parent as d8fa^2 so you can see which files changed with respect to each with:

git diff --stat d8fa^1 d8fa

... and:

git diff --stat d8fa^2 d8fa

Or you can see these both in one go with:

git whatchanged -1 -m --stat d8fa

(You can change --stat to -p to see the full diffs instead of the diffstat with git whatchanged, or just leave out the --stat with git diff. If you just want to see a single file's diff against one parent, you could do git diff d8fa^1 d8fa -- README.txt, for example.)

In most cases this output probably isn't very interesting - these will mostly be changes which were introduced in one parent but not the other. However, it's also worth checking the output of git show d8fa - this will only show a patch as part of its output if there were changes introduced by the merge that didn't seem to be in either parent, sometimes known as an evil merge.

Mark Longair