How can I find out which Git commits cause conflicts?

 ̄綄美尐妖づ 提交于 2019-11-30 06:53:24

You can gives 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.

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 to BRANCH1. 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.

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

Warning about force pushing rewritten commits

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!