Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect conflict between two git repositories.

To implement github like fork/pull request function in my project, the auto-merge feature need to detect conflict between source/target repository every time while viewing the pull request.

One solution comes to me is to analyze the 'git request-pull' output. Is there any easier method to detect the conflict?

like image 337
stcatz Avatar asked Apr 24 '12 02:04

stcatz


People also ask

How do you check if there are conflicts in Git?

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 .


2 Answers

I have deleted my previous answer, I didn't understand the question ...

Now here's the shiny new answer:

git merge --ff-only <branch>

If there are no conflicts, it will do a merge. With a conflict, it gives you a message: Not possible to fast-forward. The console return code (echo $?) is 128 in this situation.

like image 199
silvio Avatar answered Sep 20 '22 15:09

silvio


We've created a git-conflict-detector that check the latest pushed commit vs all existing branches.

It's a simple single script that is initiated by GitHub WebHook URL and even know to sent an HiChat notification when conflict is detected.

We based our solution on analyzing the git merge --ff-only <branch> output as you can see here

We've open source it so all can enjoy, learn and contribute.

like image 26
Adamski Avatar answered Sep 16 '22 15:09

Adamski