如何在 mergetool 期间 select 整个 REMOTE 文件?

How to select the entire REMOTE file during mergetool?

我正在使用 CLI mergetool vimdiff 而不是逐行输入 :diffg RE 对 select REMOTE 版本的每次更改,有没有办法我可以将整个文件的远程版本作为目标合并?

(CLI 替代方案)

我知道它并没有真正回答你的问题,但如果你需要的是从一侧获取合并中特定冲突文件的所有内容 ,您甚至不需要工具。

你可以检查你想要的文件版本(检查文档here and there)然后add它来解决冲突:

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

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

请注意,如果您后悔该移动,您也可以将其恢复到带有冲突标记的未合并状态,

git checkout -m path/to/file

简答:

使用:%diffget获取所有区块。


解释:

diffget 与大多数 vim 命令一样采用一个范围。引用 vim帮助:

                                                        :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.

% 用作范围时“等于 1,$(整个文件)”,参见 :help :%.

在 mergetool 中,如果你有超过 2 个缓冲区,你不能使用 :diffget,因为 Vim 不知道从哪个文件中获取差异。

但是,当您解决冲突时(您需要 mergetool 运行),您有一些由 Git 创建的文件来管理冲突:

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

他们代表了冲突的不同方面:

  • BACKUP 是带有冲突标记的文件副本,
  • LOCAL 是您在冲突前的当前状态,
  • BASE 包含文件在您的本地文件和正在合​​并的文件之间的共同祖先提交时的状态(或在 rebase、cherry-pick 或 stash pop/apply 的情况下应用),
  • REMOTE 是尝试应用的提交 <--- 这是您需要的版本

所以你可以做的是复制_REMOTE_文件作为你当前的(cp path/to/file_REMOTE_* path/to/file),或者在mergetool中,复制_REMOTE_的内容(:%y ) 并用它替换文件的内容(ggVGp,转到顶部,进入可视行模式,转到末尾,粘贴)。