You might want to try out smerge-mode
just open the conflicted file and do M-xsmerge-mode
RET. It will highlight all the conflicted regions. It also adds keybindings to easily resolve the conflicts, consult its documenation C-hfsmerge-mode
RET to know them.
Default prefix
I find the default prefix for smerge-mode
C-c^ cumbersome so I have changed it to C-cv
(setq smerge-command-prefix "\C-cv")
Important keybindings
For me the most important bindings are:
smerge-next
bound to smerge-command-prefixn to move to next conflict.
smerge-previous
bound to smerge-command-prefixp to move to previous conflict.
smerge-keep-current
bound to smerge-command-prefixRET to keep the version the cursor is on.
smerge-keep-mine
bound to smerge-command-prefixm to keep your changes.
smerge-keep-other
bound to smerge-command-prefixo to keep other changes.
smerge-ediff
bound to smerge-command-prefixE to start an ediff session to merge the conflicts. This is same as vc-resolve-conflicts
(thanks @phils and @Malabarba for pointing this out).
Enabling smerge-mode automatically
UPDATE: The following is relevant only on Emacs versions before 25.1
, the following can cause problems on later versions, see https://github.com/magit/magit/issues/3897
Additionally you might be interested in automatically enabling smerge-mode
when visiting a file/buffer with conflict markers you can use something like the following to achieve this
(defun my-enable-smerge-maybe ()
(when (and buffer-file-name (vc-backend buffer-file-name))
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^<<<<<<< " nil t)
(smerge-mode +1)))))
(add-hook 'buffer-list-update-hook #'my-enable-smerge-maybe)
Note that I am using buffer-list-update-hook
and not find-file-hook
since most of the times I get conflicts in a buffer which is already open in emacs in which case find-file-hook
is of no help.
Also check other methods mentioned in this answer.
e
on files shown as conflicting. Magit would launchediff
to do the merging and prompt you afterwards to confirm your changes, then you could stage the merged file.smerge
andvc-resolve-conflict
, as well as one onediff
) and has been around longer. I agree that the first thread could use a better title, though.