为什么 git mergetool 在 vimdiff 中打开 4 个窗口?(我希望 3)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7309707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does git mergetool opens 4 windows in vimdiff? (I'd expect 3)
提问by Lai Yu-Hsuan
When I met a conflict, I tried to use git-mergetool
to solve it. I typed:
当我遇到冲突时,我试图用git-mergetool
它来解决它。我输入:
>git mergetool -t vimdiff
It opened vimdiff
in 4-way, not 3-way. My split windows in vimdiff look like:
它vimdiff
以 4 向打开,而不是 3 向打开。我在 vimdiff 中的拆分窗口如下所示:
:ls
1 #a "Gemfile.lock" line 1
2 %a "Gemfile.lock.LOCAL.4828.lock" line 1
3 a "Gemfile.lock.BASE.4828.lock" line 0
4 a "Gemfile.lock.REMOTE.4828.lock" line 0
What are they? I want a 3-way diff: target file, merge file and working file. How should I configure my git or vimdiff?
这些是什么?我想要一个三向差异:目标文件、合并文件和工作文件。我应该如何配置我的 git 或 vimdiff?
回答by Peter Rincker
As an alternative, have you thought about using fugitive?
作为替代方案,您是否考虑过使用fugitive?
I'm not going to lie to you; fugitive.vim may very well be the best Git wrapper of all time.
我不会骗你;fugitive.vim 很可能是有史以来最好的 Git 包装器。
There is a an excellent vimcast, Fugitive.vim - resolving merge conflicts with vimdiff, by Drew Neil. This is part of a series on fugitive.
有一个出色的 vimcast,Fugitive.vim - 解决与 vimdiff 的合并冲突,由 Drew Neil编写。这是逃犯系列的一部分。
The Vimcastswebsite is a good place to learn more about vim.
该Vimcasts网站了解更多关于vim的一个好地方。
To use fugitive as you mergetool you can use the following.
要在合并工具时使用逃犯,您可以使用以下内容。
git config --global mergetool.fugitive.cmd 'vim -f -c "Gdiff" "$MERGED"'
git config --global merge.tool fugitive
Note: you may want to change vim
to mvim
or gvim
.
注意:您可能想要更改vim
为mvim
或gvim
。
Fugitive has a lot more to offer than just being a merge tool script so make sure you read the documentation and/or check out the vimcasts.
Fugitive 提供的不仅仅是一个合并工具脚本,因此请确保您阅读文档和/或查看 vimcast。
回答by Dr Beco
After lots of research for issuing mergetool with vimdiff and only 3 windows, I came up with this configuration, that allows me to chose when I want 3 windows or the default 4 windows:
在对使用 vimdiff 和只有 3 个窗口发布合并工具进行了大量研究之后,我想出了这个配置,它允许我选择何时需要 3 个窗口或默认的 4 个窗口:
git config --global merge.tool vimdiff
git config --global alias.mt mergetool
git config --global mergetool.merge3.cmd 'vim -d -c "wincmd l" "$LOCAL" "$MERGED" "$REMOTE"'
git config --global alias.m3 'mergetool -t merge3'
Now you can start 3 windows just typing:
现在您只需键入以下内容即可启动 3 个窗口:
git m3
And the default (4 windows) will still works as expected with:
默认(4 个窗口)仍将按预期工作:
git mt
Also, you probably would like to add this lines to the end of your ~/.vimrc
or /etc/vim/vimrc
此外,您可能希望将此行添加到您~/.vimrc
或/etc/vim/vimrc
" shortcuts to vimdiff
let mapleader=','
let g:mapleader=','
if &diff
map <leader>1 :diffget LOCAL<CR>
map <leader>2 :diffget BASE<CR>
map <leader>3 :diffget REMOTE<CR>
endif
This will create shortcuts like ,1
to grab from left, ,3
to grab from right (in both modes) and also ,2
to grab from base (center window) in the 4 windows mode.
这将创建快捷方式,例如,1
从左侧,3
抓取、从右侧抓取(在两种模式下)以及,2
在 4 窗口模式下从底部(中心窗口)抓取。
That helps a lot!
这有很大帮助!
My ~/.gitconfig
file looks like this:
我的~/.gitconfig
文件看起来像这样:
[user]
name = Dr Beco
email = my@email
[merge]
tool = vimdiff
[mergetool "merge3"]
cmd = vim -d -c \"wincmd l\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"
[alias]
lo = log --pretty=format:\"%h %ce %cd %s\" --graph
co = checkout
ci = commit
cm = commit -a -m
st = status
br = branch
m3 = mergetool -t merge3
mt = mergetool
[diff]
tool = vimdiff
I hope this helps you (and those who get to here).
我希望这对你(以及那些来到这里的人)有所帮助。
回答by VonC
Note: while you can use only 3 Windows as described in Dr Beco's answer
(vim -d -c "wincmd l" "$LOCAL" "$MERGED" "$REMOTE"'
),
the 4-windows mode is enhanced with git 2.8(March 2016)
注意:虽然如Beco 博士的回答
( vim -d -c "wincmd l" "$LOCAL" "$MERGED" "$REMOTE"'
) 中所述,您只能使用 3 个 Windows ,
但 git 2.8(2016 年 3 月)增强了 4 个窗口模式
See commit 2300328(29 Jan 2016) by Dickson Wong (diwo
).
(Merged by Junio C Hamano -- gitster
--in commit 82c17b7, 17 Feb 2016)
请参阅Dickson Wong ( ) 的commit 2300328(2016 年 1 月 29 日)。(由Junio C Hamano合并-- --在82c17b7 提交中,2016 年 2 月 17 日)diwo
gitster
The
vimdiff
backend for "git mergetool
" has been tweaked to arrange and number buffers in the order that would match the expectation of majority of people who read left to right, then top down and assign buffers 1 2 3 4 "mentally" to local base remote merge windows based on that order.
vimdiff
"git mergetool
"的后端已经过调整,以符合大多数从左到右阅读的人的期望的顺序排列和编号缓冲区,然后自上而下并将缓冲区 1 2 3 4 “精神上”分配给本地基础远程合并窗口基于那个顺序。
Internally, git will now use:
在内部,git 现在将使用:
"$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
"$LOCAL" "$BASE" "$REMOTE" "$MERGED"
instead of:
代替:
"$merge_tool_path" -f -d -c 'wincmd J' \
"$MERGED" "$LOCAL" "$BASE" "$REMOTE"
mergetool
: reorder vim/gvim buffers in three-way diffsWhen invoking default (g)
vimdiff
three-way merge, the merged file is loaded as the first buffer but moved to the bottom as the fourth window.
This causes a disconnect betweenvim
commands that operate on window positions (e.g. CTRL-W_w) and those that operate on buffer index (e.g. do/dp).This change reorders the buffers to have the same index as windows while keeping the cursor default to the merged result as the bottom window.
mergetool
: 在三向差异中重新排序 vim/gvim 缓冲区调用默认 (g)
vimdiff
三路合并时,合并文件作为第一个缓冲区加载,但作为第四个窗口移动到底部。
这会导致vim
操作窗口位置(例如CTRL- W_w)的命令和操作缓冲区索引(例如do/ dp)的命令之间断开连接。此更改将缓冲区重新排序以具有与窗口相同的索引,同时将光标默认为合并结果作为底部窗口。
回答by e3matheus
Modifying a bit the commands from this page:
稍微修改一下这个页面的命令:
git config --global mergetool.vimdiff3.cmd 'vim -f -d "$LOCAL" "$MERGED" "$REMOTE"'
git config --global merge.tool vimdiff3
- 'Merged' would be your working copy.
- 'Local' the file that is in the branch you are trying to make the changes
- 'Remote' the file from the branch you are trying to merge with.
- “合并”将是您的工作副本。
- “本地”是您尝试进行更改的分支中的文件
- 从您尝试合并的分支“远程”文件。
And then you execute the command: git mergetool
.
然后你执行命令:git mergetool
.
Note: I use fugitivealso and highly recommend it.
注意:我也使用逃犯并强烈推荐它。
回答by Greg Sexton
I'll second the fugitive recommendation.
我会支持逃犯的建议。
You could also try out splice.vim. It's a Vim plugin designed to act as a git or mercurial mergetool drop-in replacement. It allows you to easily shuffle various views of the conflict. It's also very quick, straightforward and does a good job at making merging more intuitive. Here's a screencast.
你也可以试试splice.vim。它是一个 Vim 插件,旨在充当 git 或 mercurial 合并工具的替代品。它使您可以轻松地对冲突的各种观点进行洗牌。它也非常快速、直接,并且在使合并更加直观方面做得很好。这是一个截屏视频。
The files you've listed are:
您列出的文件是:
- The local file containing the conflict.
- The file in the branch you're merging into.
- The file in the branch you're merging from.
- The file as it was in both branch ancesestor node. This file is very useful for figuring out what's going on!
- 包含冲突的本地文件。
- 您要合并到的分支中的文件。
- 您要合并的分支中的文件。
- 在两个分支祖先节点中的文件。这个文件对于弄清楚发生了什么非常有用!
Hope this helps.
希望这可以帮助。