简体   繁体   中英

How does github finds If two branches has conflict before actually merging them?

In the pull request option. Upon selecting two branch, github notifies if the two branches has any conflict. What is the command to find branch conflict?

git merge-tree

To compute the merge results of 2 revisions without making real changes:

git merge-tree $(git merge-base <rev1> <rev2>) <rev1> <rev2>

The 2 revisions have at least 1 common ancestor. If there're conflicts, the marks like <<<<<<< , ======= , >>>>>>> will be printed.

Suppose you want to check for conflict of 'dev' branch merging into the 'master' branch, then first check out to the 'master' branch and then use the merge command as mentioned below:

$ git checkout master
$ git merge branch2 --no-ff --no-commit

There's complex logic that goes into checking for merge conflict, but cut short it compares all the newly committed files from the 'last merged commit' line by line and if there's a change in the same line in both of the branches it will mark it as conflict, as git doesn't know which one to pick.

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