简体   繁体   中英

Git: reveal potential merge/rebase conflict

Is there an easy way to detect potential merge/rebase conflict between two branches with git command? For example some files are both modified in two branches, or some files are deleted from one branch and available in another branch. What I can imagine is find common ancestor of two branches with command

git merge-base

and then list all file change status from the common ancestor to the head of the both branches, and then compare the status list to find out the potential merge point. Is this the correct way or something smarter exists? If so how to achieve it?

Thanks a lot.

There are several questions on SO similar to this one, most of them with accepted answers that tell you to do a git merge --no-commit . However, this still performs the merge in the checkout and modifies the working tree. The question, as I understand it is about detecting the conflicts.

This answer lays out a way to test for conflicts. The condensed form of the test, provided in a comment to that answer, looks like this:

git merge-tree `git merge-base branch1 branch2` branch1 branch2 \
  | grep -A3 "changed in both"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM