Present Perfect


Picture Gallery
Present Perfect

git merge conflict

Filed under: Hacking — Thomas @ 11:42


For every positive experience with git there's still more than enough negative ones to balance out.

Today, I got into the situation where I was updating my gstreamer modules and one of them was apparently still in conflict. Unhelpfully, git just says:
You are in the middle of a conflicted merge.

without telling you what to do about it.

Googling revealed lots of people in the same situation, and git reset --hard would work. It looks like that would throw away my changes though. Of course that's one way out of the conflict.

I want to know what the other way is - the one where you get a change to merge conflicts.

Apparently the conflict was in a generated config file, so naively I deleted it because I wanted to check out that file again from the repository (probably an svn-ism that stuck with me). I know that in this case I don't actually need to be able to merge my changes, but I would like to know what would have been the correct way to get out of this situation.

Here's what I tried before I gave up and did a reset:

[gst-git] [thomas@level gst-plugins-ugly]$ git pull --rebase
You are in the middle of a conflicted merge.
[gst-git] [thomas@level gst-plugins-ugly]$ git diff
diff --cc win32/common/config.h
index 18dbcc4,abf941a..0000000
deleted file mode 100644,100644
--- a/win32/common/config.h
+++ /dev/null
[gst-git] [thomas@level gst-plugins-ugly]$ git checkout win32/common/config.h
error: path 'win32/common/config.h' is unmerged
[gst-git] [thomas@level gst-plugins-ugly]$ git reset -- win32/common/config.h
win32/common/config.h: locally modified


  1. Next time just edit the file to resolve the conflict, then “git add” it, and finally “git commit” to commit the merge.

    git tells you to do that:

    $ git merge b/master
    Auto-merging test
    CONFLICT (content): Merge conflict in test
    Automatic merge failed; fix conflicts and then commit the result.

    Comment by Johannes Berg — 2009-06-02 @ 12:29

  2. Have you ever tried hg? I get the impression that fewer people have problems with it.

    Comment by Dirkjan Ochtman — 2009-06-02 @ 13:03

  3. git mergetool

    might help it goes through all the conflict and pops up merge tool like meld, or kdiff3 for every conflicted file

    hope it helps

    Comment by inkubux — 2009-06-02 @ 13:12

  4. The correct way out of that particular situation is to not keep generated files in the VCS.

    Comment by Karellen — 2009-06-02 @ 13:21

  5. Make sure you’re using the latest version of git… if you’re using an old version (and it looks like you are, based on seeing that message… and not seeing the help that Johnannes points out), it’s not as nice as it should be. There have been improvements in the past year or so.

    I’m using 1.6.3, for instance. It’s *much* friendlier than 1.5.x.

    Comment by Garrett LeSage — 2009-06-02 @ 13:32

  6. Did you try “git mergetool”. It’s quite convenient, especially after configuring “merge.tool = meld”.

    Comment by Mathias Hasselmann — 2009-06-02 @ 13:35

  7. Deleting the file still left it in a conflict state. Only now the conflict is that there were changes upstream, and you deleted it locally.

    To recover, you should have resolved the conflicts in the file. One way to do that would be by editing the file and fixing the conflict markers.

    Another way would be by removing any conflicts in your file by doing:

    $ git checkout — path/to/file

    This is the same as:

    $ git checkout HEAD — path/to/file

    which is a general form allowing you access to that file as at any commit/tag/branch, etc

    Once you have resolved the conflicts, tell git by “add”ing the files that were in conflict.

    You may also want to take a look at git’s merge tool:

    $ git mergetool

    Comment by Rogan Dawes — 2009-06-02 @ 13:49

  8. Try

    git checkout –ours win32/common/config.h

    Comment by Pieter — 2009-06-02 @ 14:39

  9. Ideally, generated files must never be version controlled. If you do that, getting into problems because of that can not possibly be blamed on the version control system.

    Comment by Zeeshan Ali (Khattak) — 2009-06-02 @ 15:40

  10. I think ‘git status’ should give you a clearer view of the situation. In a conflict merge, ‘gitk –merge’ is also a useful visualization. BTW, you’d still run into the same merge conflict if you used topic branches, but I’d still recommend them.

    Comment by Russ — 2009-06-02 @ 17:34

  11. For some reason, am not able to see the other comments. Anyways, thanks for bringing it up, i had the same issue. After removing the file, i did a git checkout to retrieve the file back after removing the conflict log from .git/ (forgot the exact patch). will need to watch for the right solution.

    Comment by Chenthill — 2009-06-02 @ 19:03

  12. I usually prefer to work in a branch, and only use master if the work is small. So in case I screw up something really bad I’ve in master a good copy that can be clone in other folder. A command I’ve recently learned to use is `git stash` to save the temporary work while doing a rebase or merging other branch.

    Comment by xhantt — 2009-06-03 @ 01:47

  13. btw, i strongly recommend using kdiff3 as mergetool. We used both meld and kdiff3, and kdiff3 has some important advantages:
    * it is a realy 3-way diff showing you the original , local and “remote” versions along with the resulting version. meld actually only shows local and remote versions, which make it hard to see how changes originated.
    * kdiff3 is very fast if you learn the shortcuts

    meld is perfect and very userfriendly if you only need 2-way diff (eg comparing 2 files on your filesystem)

    after fixing a conflict, commit immediately (git only autocommits a merge if there are no conflicts). do not wait and make some more changes, because then you will make one big commit that has both a merge and some real changes.

    Comment by frank — 2009-06-04 @ 16:34

  14. […] found this handy post, which helped a little. I found this post more useful […]

    Pingback by Git with it. You are in the middle of a conflicted merge. — sen77tech — 2011-07-07 @ 15:10

RSS feed for comments on this post. TrackBack URL

Leave a comment