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.
To see the beginning of the merge conflict in your file, search the file for the conflict marker <<<<<<< . When you open the file in your text editor, you'll see the changes from the HEAD or base branch after the line <<<<<<< HEAD .
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"
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