Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 627
Skywolf Avatar asked Feb 25 '14 08:02

Skywolf


People also ask

How do I see merge conflicts?

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 .


1 Answers

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"
like image 149
user4815162342 Avatar answered Oct 15 '22 15:10

user4815162342