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?
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 :%
.
(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
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).
© 2022 - 2024 — McMap. All rights reserved.