最终将使用哪个版本的 git 文件:LOCAL、BASE 或 REMOTE?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11133290/
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
Which version of the git file will be finally used: LOCAL, BASE or REMOTE?
提问by tsusanka
When there's a collison during git merge
, I open a mergetool called Meld. It opens three files LOCAL, BASE and REMOTE. As I've read LOCAL is my local branch, BASE is common ancestor and REMOTE is the branch to be merged.
当发生碰撞时git merge
,我打开一个名为Meld的合并工具。它打开三个文件 LOCAL、BASE 和 REMOTE。正如我所读到的 LOCAL 是我的本地分支,BASE 是共同的祖先,REMOTE 是要合并的分支。
Now to my question: which version of the file will be finally used? Is it REMOTE? If so, can I edit it as I want, regardless what's in the BASE branch for example?
现在我的问题是:最终将使用哪个版本的文件?是远程的吗?如果是这样,我可以根据需要编辑它,例如不管 BASE 分支中有什么吗?
采纳答案by Fabien Quatravaux
It's the one in the middle : BASE
.
这是中间的那个:BASE
。
In fact, BASE
is not the common ancestor, but the half-finished merge where conflicts are marked with >>>>
and <<<<
.
其实BASE
不是共同的祖先,而是用>>>>
和标记冲突的半成品合并<<<<
。
You can see the file names on the top of meld editing window.
您可以在融合编辑窗口的顶部看到文件名。
You can edit the BASE
file as you want with or without using meld commands.
You can also get rid of meld and just edit the file with your favorite text editor.
您可以BASE
使用或不使用 meld 命令根据需要编辑文件。
您也可以摆脱 meld 并使用您喜欢的文本编辑器编辑文件。
- The code between
<<<< HEAD
and=====
markers is the one of your local file before the merge. - The code between
====
and>>>> <branch name>
is the one of the remote file.
<<<< HEAD
和=====
标记之间的代码是合并之前的本地文件之一。====
和之间的代码>>>> <branch name>
是远程文件之一。
回答by Tomek Bury
Meld has a hidden 3-way merge featureactivated by passing in the 4th parameter:
Meld 有一个隐藏的 3 路合并功能,通过传入第 4 个参数激活:
meld $LOCAL $BASE $REMOTE $MERGED
The right and left panes are opened in read-only mode, so you can't accidentally merge the wrong way around. The middle pane shows the result of merge. For the conflicts it shows the base version so that you can see all the important bits: original text in the middle, and conflicting modifications at both sides. Finally, when you press the "Save" button, the $MERGED file is written - exactly as expected by git.
左右窗格以只读模式打开,因此您不会意外合并错误的方式。中间窗格显示合并的结果。对于冲突,它显示了基本版本,以便您可以看到所有重要的部分:中间的原始文本和两侧的冲突修改。最后,当您按下“保存”按钮时,将写入 $MERGED 文件 - 完全符合 git 的预期。
The ~/.gitconfig file I use contains the following settings:
我使用的 ~/.gitconfig 文件包含以下设置:
[merge]
tool = mymeld
conflictstyle = diff3
[mergetool "mymeld"]
cmd = meld --diff $BASE $LOCAL --diff $BASE $REMOTE --diff $LOCAL $BASE $REMOTE $MERGED
this opens meld with 3 tabs, 1st and 2nd tab containing the simple diffs I'm trying to merge, and the 3rd tab, open by default, shows the 3-way merge view.
这将打开包含 3 个选项卡的合并,第一个和第二个选项卡包含我尝试合并的简单差异,第三个选项卡默认打开,显示 3 向合并视图。
Now, the reason the feature is hidden is that it's not polished enough yet. It's very useful as it is now, but Kai Willadsen, the meld author, pointed to few wrinkles that need ironing out. For example there's no GUI to start the 3-way merge mode, command line syntax is a bit arcane, and such. If you speak python and have some time on your hands - you know what to do.
现在,隐藏该功能的原因是它还不够完善。它现在非常有用,但融合作者凯威拉森指出,很少有皱纹需要消除。例如,没有启动 3 路合并模式的 GUI,命令行语法有点神秘,等等。如果你会说 python 并且有时间 - 你知道该怎么做。
Edit: In newer versions of Meld, the synax has changed slightly. This was in the comments, but it belongs in the answer.
编辑:在较新版本的 Meld 中,synax 略有变化。这是在评论中,但它属于答案。
The meld command now uses the --output option, so the last line from the snippet above should be:
meld 命令现在使用 --output 选项,所以上面代码片段的最后一行应该是:
cmd = meld --diff $BASE $LOCAL --diff $BASE $REMOTE --diff $LOCAL $BASE $REMOTE --output $MERGED
回答by user1284631
There are 4 files involved:
涉及4个文件:
$LOCAL
The file on the branch where you are merging; untouched by the merge process when shown to you$REMOTE
The file on the branch from where you are merging; untouched by the merge process when shown to you$BASE
The common ancestor of $LOCAL and $REMOTE, ie. the point where the two branches started diverting the considered file; untouched by the merge process when shown to you$MERGED
The partially merged file, with conflicts; this is the only file touched by the merge process and, actually, never shown to you inmeld
$LOCAL
您要合并的分支上的文件;向您展示时未受到合并过程的影响$REMOTE
您要合并的分支上的文件;向您展示时未受到合并过程的影响$BASE
$LOCAL 和 $REMOTE 的共同祖先,即。两个分支开始转移考虑文件的点;向您展示时未受到合并过程的影响$MERGED
部分合并的文件,有冲突;这是合并过程中唯一涉及的文件,实际上从未在meld
The $MERGED
file is the one that contains the <<<<<<
, >>>>>>
, =====
(and, maybe, ||||||
) markers (that delimit conflicts). Thisis the file that you edit manuallyto correct conflicts.
该$MERGED
文件是包含<<<<<<
, >>>>>>
, =====
(和,也许,||||||
)标记(分隔冲突)的文件。这是您手动编辑以更正冲突的文件。
The manual conflicts editing and the visual conflicts editing are done on different files and presented different informations.
手动冲突编辑和可视化冲突编辑在不同的文件上完成并呈现不同的信息。
When using the mergetool (assume meld
), the files that are seeing therein are: $LOCAL
, $BASE
, $REMOTE
. Note that you don't see the $MERGED
file, although this is passed as a hidden parameter to meld
to write the result of the edit there.
使用合并工具(假设meld
)时,在其中看到的文件是:$LOCAL
, $BASE
, $REMOTE
. 请注意,您看不到该$MERGED
文件,尽管它作为隐藏参数传递给以在meld
那里写入编辑结果。
In other words, in meld
, you are editing the file in the middle, the $BASE
file, and you pick all the changes from left or from the right manually. It is a clean file, not touched by the merge process. The only glitch is that, when you save, you do not save into the $BASE
file, but in the fourth hidden parameter of meld
, that is the $MERGED
file (that you do not even see). The $BASE
file does notcontain any conflicts or partial successful merges because it is not the $MERGED
file.
换句话说,在 中meld
,您正在编辑中间的$BASE
文件,该文件,并手动从左侧或右侧选择所有更改。它是一个干净的文件,没有被合并过程触及。唯一的小故障是,当您保存时,您没有保存到$BASE
文件中,而是保存在 的第四个隐藏参数中meld
,即$MERGED
文件(您甚至看不到)。该$BASE
文件并没有包含任何冲突或部分成功的合并,因为它不是$MERGED
文件。
In the visual editing, when presenting to you the $BASE
file (instead of the $MERGED
file) git
basically discards all its attempts to do the merging (those attempts are visible, if you want, in the $MERGED file) and lets you to completelydo the merging from scratch.
在可视化编辑中,当向您展示$BASE
文件(而不是$MERGED
文件)时,它git
基本上会放弃所有进行合并的尝试(如果需要,这些尝试在 $MERGED 文件中可见)并让您完全进行合并从头开始。
The bottom line is that in manual and visual merging conflicts you are not looking at the same files, but the final result is written in the same file (that is the $MERGED
file).
最重要的是,在手动和可视化合并冲突中,您不是查看相同的文件,而是将最终结果写入相同的文件(即$MERGED
文件)中。
The manual correction of the conflicts is done on $MERGED
because git
has no meanto present you three files, so it squashes the information from the three files ($LOCAL
, $BASE
, $REMOTE
) in that $MERGED
file.
手动更正冲突是$MERGED
因为git
没有办法向您显示三个文件,因此它会压缩该文件中三个文件 ( $LOCAL
, $BASE
, $REMOTE
) 中的信息$MERGED
。
But the visual tools have the meansto show you three files: they show you the $LOCAL
, $BASE
, $REMOTE
files. You are picking changes from the $LOCAL
and $REMOTE
files and you are bringing those into the $BASE
file, completely re-building and even overwriting the failed attempt of merging that is the $MERGED
file.
但是可视化工具可以向您显示三个文件:它们向您显示$LOCAL
, $BASE
,$REMOTE
文件。您正在从$LOCAL
和$REMOTE
文件中挑选更改并将它们带入$BASE
文件,完全重新构建甚至覆盖合并该$MERGED
文件的失败尝试。
回答by Saad Malik
Cosmin's solution works, but the $BASEfile is updated--not $MERGED. This will update the $MERGEDfile:
Cosmin 的解决方案有效,但$BASE文件已更新 - 而不是$MERGED。这将更新$MERGED文件:
Meld: v1.8.4
融合: v1.8.4
[merge]
conflictstyle = diff3
tool = mymeld
[mergetool "mymeld"]
cmd = meld --auto-merge --output $MERGED $LOCAL $BASE $REMOTE --diff $BASE $LOCAL --diff $BASE $REMOTE
回答by lumbric
With Meld 1.7the Solution by Tomek Bury does not work anymore.
在Meld 1.7中,Tomek Bury 的解决方案不再起作用。
The default settingsdidn't satisfy me:
在默认设置并不能满足我:
Instead for Meld >=1.7I suggest one of two other solutions.
对于Meld >=1.7,我建议使用其他两种解决方案之一。
First solution:
第一个解决方案:
meld $LOCAL $BASE $REMOTE --auto-merge
Second solution:
第二种解决方案:
meld $LOCAL $MERGED $REMOTE
.gitconfig
.gitconfig
Copy & paste this in your .gitconfig
file to get the solutions as described above:
将其复制并粘贴到您的.gitconfig
文件中以获得上述解决方案:
[merge]
tool = meld16
[mergetool "meld17"]
# use this for Meld >=1.7
# see http://stackoverflow.com/a/22911793/859591
# second solution:
cmd = meld $LOCAL $MERGED $REMOTE
# first solution:
#cmd = meld $LOCAL $BASE $REMOTE --auto-merge
[mergetool "meld16"]
cmd = meld --diff $BASE $LOCAL --diff $BASE $REMOTE --diff $LOCAL $BASE $REMOTE --output $MERGED
[include]
# requires git v1.7.10+
path = .gitconfig.local
Copy & paste this in a .gitconfig.local
file to set meld17 or meld16 only for this machine in case you use your .gitconfig on multiple machines:
.gitconfig.local
如果您在多台机器上使用您的 .gitconfig,复制并粘贴到一个文件中,只为这台机器设置 meld17 或 meld16:
# This is a host specific config file!
# Note that git 1.7.10+ is needed
# http://stackoverflow.com/a/9733277/859591
[merge]
tool = meld17
回答by Thomas Leonard
I found that none of the default files shown was being saved.
meld was showing $LOCAL
, $REMOTE
and $BASE
by default. To make it work, I needed to make meld show $MERGED
instead of $BASE
. Putting this in my ~/.gitconfig
fixed it for me:
我发现没有保存显示的默认文件。MELD被显示$LOCAL
,$REMOTE
并$BASE
在默认情况下。为了让它发挥作用,我需要制作 meld show$MERGED
而不是$BASE
. 把它放在我的~/.gitconfig
固定它为我:
[merge]
tool = mymeld
[mergetool "mymeld"]
cmd = meld "$LOCAL" "$MERGED" "$REMOTE"
I'm using Arch, with:
我正在使用 Arch,与:
$ git --version
git version 1.8.2
$ meld --version
meld 1.7.1
回答by wnasich
For some reason newest versions of meld does not display marker lines added for conflicts (<<<<<<<, =======, >>>>>>>) . If you want to see those lines, you should to install meld v 1.3.3 or previous.
出于某种原因,最新版本的 meld 不显示为冲突添加的标记线 (<<<<<<<, ========, >>>>>>>) 。如果您想查看这些行,您应该安装 meld v 1.3.3 或更低版本。
回答by cosmin
Please see Saad's answer for the correct answer.
请参阅 Saad 的答案以获取正确答案。
With meld 1.8.1 on Ubuntu I was getting the
在 Ubuntu 上使用 meld 1.8.1 我得到了
wrong number of arguments supplied to --diff
提供给 --diff 的参数数量错误
and adding the --output before $MERGED fixed it for me:
并在 $MERGED 为我修复它之前添加 --output :
[mergetool "mymeld"]
cmd = meld --diff $BASE $LOCAL --diff $BASE $REMOTE --diff $LOCAL $BASE $REMOTE --output $MERGED