tags:

views:

2703

answers:

3

At some point in our past branches of development in git were merged. However, the wrong merge decision was made and therefore some code didn't make it into master branch that we expected would be there. (There were multiple merges of different branches before a final merge to a master branch. So the branching and merging history was fairly complex.)

Is there an easy way to search a git repository to determine on which merge the "wrong" decision was made on?

(I already know the answer for this particular case, but the process of finding it was a bit tedious.)

EDIT: The reason git blame proved inadequate is that the line was touched in a commit sometime after the merge error.

+8  A: 

Can git-bisect help in your case?

J.F. Sebastian
+6  A: 

If you know a line in a file that was modified by the git branch merge, you can do 'git blame file.txt' and determine the commit hash number and commit author of the line in the file. Then you can go through the git log and pull up the exact commit associated with the bad branch merge.

EDIT: In response to the author's comments, if you're looking for the disappearance of a certain line then 'git diff' combined with grep and binary search could be what you want. let's say you have commit numbers 0,1,2,3,4,5,6. You know that the line existed in revision 0, but disappeared in revision 6. Use 'git diff' plus grep to search for the disappearance.

git diff 0 6 | grep '- line I care about'

The first iteration, you'll see the line you care about disappearing. Then you cut the revision number in half and try again

git diff 0 3 | grep '- line I care about'

If the grep still shows the line disappearing ( with the '-' sign), then you know that the line disappeared in revision 0 to 3. If the grep doesn't show the line disappearing, then the line disappeared in revisions 4-6.

Keep cutting the revisions in half until you find the culprit.

Ross Rogers
The problem was that the line was touched sometime after the "merge error". I knew when the patch was introduced but couldn't easily tell when it first dropped out.
Atlas1j
+6  A: 

Without more details I can only hint at possible solutions. If you know the file or line affected, you can try either git-blame ("git blame file", or "git blame revision file"), or you can try so called 'pickaxe search' with git-log, i.e. "git log -S'line'" trying to find revision which introduced given line, or deleted given line. You can find and examine all merges, for example via "git log -p -m --grep=Merge", and examine how they relate to their parents ('-m' show diffs to all parents; alternatively '-c' shows combined diff but doesn't show trivial merge changes, i.e. if one side was taken).

Jakub Narębski