Reputation: 438
I'm merging upstream changes to my project, and recently there were a lot of commits that created a lot of merge conflicts. It doesn't make sense to try to resolve them all at once.
How can I find out which commits create a conflict? Any of the following are acceptable:
Upvotes: 29
Views: 11984
Reputation: 46992
Note: git-mergemate has since been renamed to git-imerge.
Michael Haggerty also has a tool called git-mergemate
that has a find-conflict
command:
git-mergemate find-conflict BRANCH1..BRANCH2
Use bisection to determine the earliest commit on
BRANCH2
that causes a conflict when merged toBRANCH1
. Don't actually retain any merges.
git-mergemate find-conflict BRANCH1...BRANCH2
Use bisection to find a pair of earliest commits (one from each branch) that do not merge cleanly. Don't actually retain any merges.
git imerge
can be used to do an incremental merge and resolve conflicts along the way, though it does not have the equivalent of find-conflicts
in git-mergemate
.
Upvotes: 7
Reputation: 1323075
You can give git imerge a try: that will apply your commits one by one, giving you the chance to do a rebase incrementally (meaning you can start a rebase, interrupt it, resume it later!).
You can see here a comparison between Incremental merge vs. direct merge vs. rebase.
Upvotes: 21
Reputation: 15155
You can use git log --merge
to see all conflicted commits when trying to merge another branch into current branch.
# find all conflicted files
git merge --no-commit --no-ff other_branch | grep "CONFLICT"
# find all commits from 'other_branch' that causes the conflicts
git log --merge | grep commit
# abort "--no-commit" command above, because we only want to test and see
git merge --abort
It will produce something like:
commit bb713a4f01e4e55a2b297f7facf962090c11687f
commit 280d44bd8a569108319080633714fa8398eab3c4
commit 3a99961983f5d3ef4508d2a8457309f779650f68
commit 87239c7fef291206063e2c840270298556ee0ef4
commit f4e27e2d5753a9eaf375da66bc8a3d589a22ba23
commit c4365a21bb85a43f227047ecdda789320aa12918
commit 78572542cf08eb8d61a40b20c12cf11357eeb3df
commit cfbc6ffe334ed5748bd3988d3b48ab42a48eeb6a
commit 88a273099afb49b968ebf4c0c3602a334ef0b2d8
Executing git log --merge
without starting a merge (git merge
) will produce the following error:
fatal: --merge without MERGE_HEAD?
This command can be executed within the merge process only.
Upvotes: 4
Reputation:
Is there any reason why you wouldn't just want to use rebase
(non-interactively) to sync up with changes in the upstream branch? It will stop if there is a conflict on each commit, and then you can resume the rebase when it's resolved. It's like incremental merging, and it's built right into Git, there's no need for an external plugin/tool:
git fetch <remote>
git rebase <remote>/<upstream-branch>
# Conflict on commit X, resolve conflict, then continue the rebase
git rebase --continue
Note, of course, that rebasing your local branch will change the sha IDs of its commits. If you've already pushed the commits that you want to rebase to your remote, then you'll need to force push the new commits to overwrite the old ones, which might pose a potential problem if you're sharing your branch with other people. You can learn more about these problems in:
Upvotes: 0