23

Let's say I have a merge conflict. I see a conflicted file like this:

Unstaged changes:
    Unmerged   Foo/bar/wibble/plop/elbow.txt

I can hit tab here to open the changes and maybe jump to a point inside the file to fix by hand, but if it's a big file with lots of conflicts that can be time consuming.

How can I ask git, through magit, to checkout the ours or theirs version of the file, to resolve the conflict? I can copy the path, then use Shift-: to enter a custom git command, but it seems like there must be a keyboard shortcut for this. I can't see anything obvious in the magit menu or the ? pop-up.

tenpn
  • 395
  • 2
  • 14
  • 3
    While this does not directly answer your question, but it could be useful. Move point on the conflict file in `magit-status` and press `e` to start 3-way merging with `ediff`. Another alternative is that in a conflict buffer, you can turn on `smerge-mode` for conflict highlighting and perform interactive merging right in your buffer (not ediff). The prefix key binding for `smerge-mode` related commands is `C-c ^`; you can press `C-c ^ C-h` to view all key bindings. – Tu Do Nov 26 '14 at 12:21
  • I don't find "ours" or "theirs" in the doc either. http://magit.github.io/master/magit.html#Pushing-and-Pulling – Ehvince Nov 26 '14 at 14:53
  • 1
    Looks like a good question to open a feature request ? – Ehvince Nov 27 '14 at 09:49
  • 1
    good idea @Ehvince, done: https://github.com/magit/magit/issues/1643 – tenpn Nov 27 '14 at 15:04
  • Great ! I'll follow the thread too. – Ehvince Nov 27 '14 at 15:10
  • 1
    Oooh: in the Next version of magit you can `k` on a confict and choose which version to keep. Sounds perfect! https://github.com/magit/magit/issues/1643 – tenpn Nov 27 '14 at 15:25

2 Answers2

31

I'm not sure when this feature was added, but it does this perfectly:

  1. Merge one branch into another and encounter a conflict
  2. In the Magit buffer, there will be sections for Merging master, and Unstaged changes, Staged changes. The conflicted file is in Unstaged changes
  3. On the line with the conflicted file, hit k to discard the changes (i.e., the conflicted changes)
  4. In the minibuffer, you will see the answer:

For <conflicted file> checkout: [o]ur stage, [t]heir stage, [c]onflict, or [C-g] to abort

Hut8
  • 658
  • 6
  • 11
7

There are several solution:

  • use smerge-ediff. In the file with the conflict, you run M-x smerge-ediff. It will put you in the ediff resolve mode, with four open buffer: yours, theirs, merge, and the command buffer. In the command buffer, you use n and p to go to next or previous hunk, "a" or "b" to accept change from the first or second buffer, or you can go to the merge buffer, and edit it to your liking.
  • use ediff from magit, with e on the stable version of magit, or M-e or M-m (magit-ediff-resolve) in the next branch of magit, and then you will find yourself mostly like in the first case
  • there is also smerge-mode, C-c ^ n and C-c ^ p will help you go from an hunk to the previous or next one, you can then edit them, or use C-c ^ o to keep the 'other' version, C-c ^ m to keep the 'mine' version, C-c ^ b to keep the old version and C-c ^ a to keep them all.
  • you can use magit-find-file to open a file as it was in some commit.
Rémi
  • 1,607
  • 11
  • 13
  • I hadn't seen that Tu Do already had most the answer I post here. Sory – Rémi Nov 26 '14 at 17:27
  • Thanks for the comprehensive list, but I guess the answer to "is there a concise way to get the Ours or Thiers version" is no. :( – tenpn Nov 27 '14 at 14:57