4

When merging conflicts In smerge mode, how to select "mine" for all conflicts? At the moment I only know how to do it one by one with smerge-use-lower or C-c ^ l.

Update: a possible solution using Magit?

I just found basically the same question on Reddit: https://www.reddit.com/r/emacs/comments/18h0u9v/smerge_keep_lower_for_entire_file/, although I've not figured out how the solution there works. It uses the 'k' key with Magit.

Also, it seems it could be done from the "Magit mini-buffer"? Not sure how though. https://github.com/magit/magit/issues/4458

1 Answer 1

5

Sure, the following function works for me to automatically resolve all conflicts inside a file:

(defun smerge-resolve-all-in-file-to (to-keep) "Resolves all conflicts inside a file in preference of TO-KEEP TO-KEEP decides which part to keep and is one of `upper', `lower', `base'" (interactive (list (completing-read "Keeping (upper, base, lower): " '(upper base lower)))) (let ((resolve-func (pcase to-keep ("upper" 'smerge-keep-upper) ("base" 'smerge-keep-base) ("lower" 'smerge-keep-lower) (_ (error "Unknown resolution argument!")))) (num-chars-bfore (point-max))) (save-excursion (goto-char (point-min)) (while (ignore-errors (not (smerge-next))) (funcall resolve-func))) (when (= num-chars-bfore (point-max)) (message "No conflicts were found")))) 

It is interactive with autocompletion, so you can do a M-x smerge-resolve-all-file-conflicts and it will autocomplete upper, base, lower args for you.


I also sent it upstream because I often need such functional in my work, but Emacs maintainers don't want to accept it based on their claim that they never had such a need, hence people won't use it. If you want it to be in Emacs, please voice your opinion on the issue by emailing to [email protected].

5
  • Thanks. It's a bit surprising there wasn't already a built-in a way to do it. Commented Feb 22, 2024 at 23:20
  • Also, why not adding the keywords mine and theirs too? Commented Feb 22, 2024 at 23:21
  • 1
    @qazwsx well, smerge works with upper/lower terminology (my guess is because these conflicts may be generated by other software such as Mercurial, which may have different terminology.). I can't guarantee that between git versions there is strict correlation between upper/lower and theirs/ours. Besides, "theirs/ours" is confusing, because its meaning changes between git commands, so it's not even a good terminology. Btw, I sent the patch upstream, but the discussion is still ongoing, apparently maintainers do not think it's useful. Commented Feb 23, 2024 at 7:00
  • The linked discussion was too long and complex for me to digest. Could I please get a summary from you -- is it that no existing feature help with my original need? It does require a new function like in your answer? Commented Feb 23, 2024 at 23:47
  • @qazwsx from what I understand, there was no such functional, and there also will not be unless I manage to convince them it's useful to people. Commented Feb 24, 2024 at 6:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.