Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search a git repository history to find a merge error?

Tags:

git

merge

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.

like image 803
Atlas1j Avatar asked Feb 16 '09 21:02

Atlas1j


People also ask

Does git merge keep history?

In the Conceptual Overview section, we saw how a feature branch can incorporate upstream changes from main using either git merge or git rebase . Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .

Which command is used to display merge history in git?

I'll start by showing how the default “chronological” order of git log can mislead you when the history contains merge commits. Then I'll show how you can visualize Git merge history using git log --graph , and how to see the “true” history of a single branch using --first-parent .

How do I find a merge commit?

To see the merge commit's message and other details, use git show-merge with the same arguments.

How do I merge two branches with unrelated histories?

To combine two separate Git repositories into one, add the repository to merge in as a remote to the repository to merge into. Then, combine their histories by merging while using the --allow-unrelated-histories command line option.


1 Answers

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

like image 78
Jakub Narębski Avatar answered Oct 06 '22 01:10

Jakub Narębski