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.
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 .
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 .
To see the merge commit's message and other details, use git show-merge with the same arguments.
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.
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).
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