How to select the entire REMOTE file during mergetool?
Asked Answered
V

3

13

I'm using CLI mergetool vimdiff and rather than going line by line and typing :diffg RE for every change to select the REMOTE version, is there a way I can just have the REMOTE version of the entire file as the target merge?

Vines answered 30/3, 2019 at 8:12 Comment(1)
Git lets you specify merge strategies (ours, theirs) but these affect the entire merge. Be carefulPersiflage
Y
11

Short answer:

Use :%diffget to get all chunks.


Explanation:

diffget takes - as most vim commands - a range. To quote vimhelp:

                                                        :diffg :diffget
:[range]diffg[et] [bufspec]
                Modify the current buffer to undo difference with another
                buffer.  [...]
                See below for [range].

[...]

When no [range] is given, the diff at the cursor position or just above it is
affected.  When [range] is used, Vim tries to only put or get the specified
lines.

% when used as a range is "equal to 1,$ (the entire file)", see :help :%.

Yung answered 31/3, 2019 at 13:20 Comment(0)
C
3

(CLI alternative)

I'm aware it doesn't really answer your question as is, but if what you need is to take everything from one side for a specific conflicting file in a merge, you don't even need a tool.

You can check out the file version you want (check doc here and there) and then add it to resolve the conflict :

git checkout --ours path/to/file
# or
git checkout --theirs path/to/file

# and then to conclude the resolution
git add path/to/file

Note that you can also, if you regret that move, take it back to the unmerged state with conflict markers, with

git checkout -m path/to/file
Caesarea answered 30/3, 2019 at 11:52 Comment(0)
E
1

In mergetool, if you have more than 2 buffers, you can't use :diffget, as Vim does not know from which file to get the diff from.

However, when you solve a conflict (you need to have mergetool running), you have a few files created by Git to manage the conflict:

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

    both modified:   my/conflicting/file.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .env
    my/conflicting/file.py.orig
    my/conflicting/file_BACKUP_5038.py
    my/conflicting/file_BASE_5038.py
    my/conflicting/file_LOCAL_5038.py
    my/conflicting/file_REMOTE_5038.py

They represent different sides of the conflict:

  • BACKUP is a copy of the file with the conflicts markers,
  • LOCAL is your current state before the conflict,
  • BASE contains the state of the file at the common ancestor commit between your local and the one being merged (or applied in case of rebase, cherry-pick or stash pop/apply),
  • REMOTE is the commit trying to be applied <--- which is the version you want in your case

So what you can do is to copy the _REMOTE_ file as your current (cp path/to/file_REMOTE_* path/to/file), or in mergetool, copy the content of _REMOTE_ (:%y) and replace the content of your file with it (ggVGp, go at the top, go in visual line mode, go to the end, paste).

Eveliaevelin answered 1/4, 2019 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.