git 合并冲突解决
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9207260/
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
Merge conflict resolution
提问by Chris Calo
When there's a merge conflict in Git, junk like the following is inserted into the conflicting files. Three questions:
当 Git 中出现合并冲突时,会在冲突文件中插入如下所示的垃圾。三个问题:
- How do you read these annotations?
- What are some strategies to use when fixing these merge conflicts?
- Is there a GUI tool for Mac that knows how to read these files and display the two versions side-by-side to make it easier to fix the problem?
- 你如何阅读这些注释?
- 修复这些合并冲突时要使用哪些策略?
- 是否有适用于 Mac 的 GUI 工具知道如何读取这些文件并并排显示两个版本,以便更轻松地解决问题?
Note: In case it's relevant, I am using GitHub's Mac GUI client.
注意:如果相关,我使用的是 GitHub 的 Mac GUI 客户端。
采纳答案by Chris Calo
There's now a better solution than trying to read the gibberish markers that Git inserts into your files. Kaleidoscope 2, Black Pixel's second release of their diff tool, is now also a merge tool. It's not free, but it works beautifully.
现在有一个比尝试读取 Git 插入到文件中的乱码标记更好的解决方案。Kaleidoscope 2是 Black Pixel 的第二版差异工具,现在也是一个合并工具。它不是免费的,但效果很好。
After you install Kaleidoscope 2, it's really simple to integrate with Git. Open Kaleidoscope and from the Menu Bar choose Kaleidoscope> Integration…
安装 Kaleidoscope 2 后,与 Git 集成非常简单。打开 Kaleidoscope 并从菜单栏中选择Kaleidoscope> Integration...
Then you'll see this window. Simply choose Gitfrom the left nav and then install the ksdiff
command-line tool and then make Kaleidoscope Git's default diff and merge tool.
然后你会看到这个窗口。只需从左侧导航中选择Git,然后安装ksdiff
命令行工具,然后将 Kaleidoscope Git 设为默认的 diff 和 merge 工具。
Finally, once you have a merge conflict in Git, simply go to the command line and execute git mergetool
. Now the conflict is easy to read. Enjoy.
最后,一旦在 Git 中出现合并冲突,只需转到命令行并执行git mergetool
. 现在冲突很容易理解。享受。
回答by Simon Richter
Everything between <<<<<<
and ======
comes from the HEAD
revision, which is the committed state before starting the merge operation (git merge
will complain if the tree is dirty, so it should be equivalent to your working directory).
<<<<<<
和之间的所有内容======
都来自HEAD
修订版,这是开始合并操作之前的提交状态(git merge
如果树脏了会抱怨,所以它应该相当于你的工作目录)。
The parts between ======
and >>>>>>
come from the version being merged. The text after the >>>>>>
is the comment of the commit that introduced the conflicting change.
======
和之间的部分>>>>>>
来自被合并的版本。之后的文本>>>>>>
是引入冲突更改的提交的注释。
That there is a conflict marker means that the base version of this part of the file is different from both "new" versions. The base version (last common ancestor) is not shown.
存在冲突标记意味着文件这部分的基本版本与两个“新”版本不同。未显示基本版本(最后一个共同祖先)。
If you want a more comfortable merge and have a GUI available, I suggest you take a look at kdiff3.
如果你想要一个更舒适的合并并且有一个可用的 GUI,我建议你看看 kdiff3。
回答by sparrow
<<<< HEAD #Where the conflict starts
#Previous Revision
========== # The point where things look iffy
#Things that changed
>>>>> New Commit # Point where the conflict ends
Mac's Xcode comes with FileMerge which can be accessed on the command line with opendiff
.
Mac 的 Xcode 带有 FileMerge,可以在命令行上使用opendiff
.
git mergetool -t opendiff
git mergetool -t opendiff
回答by manojlds
You can configure a (graphical) merge tool and use that tool to do the conflict resolution.
您可以配置(图形)合并工具并使用该工具来解决冲突。
Also have a look at the git mergetool
command - if you have one of the pre-defined tools installed or have configured some other tool, it will open up the tool for resolution http://schacon.github.com/git/git-mergetool.html
另请查看git mergetool
命令 - 如果您安装了预定义工具之一或配置了其他工具,它将打开用于解析的工具http://schacon.github.com/git/git-mergetool。 html
If you are interested in GUI tools, you need not worry about what the notations really mean, as the GUI tool will help you to easily make the resolutions. Just understand that the parts marked with =====
and >>>>>
are the conflict sections.
如果您对 GUI 工具感兴趣,则不必担心符号的真正含义,因为 GUI 工具将帮助您轻松做出决议。只需了解标有=====
和>>>>>
的部分是冲突部分。
回答by Nesha Zoric
When you have two branches with changes to the same file and you try to merge them, a merge conflict will occur. To see the list of conflicted files run git status
on your terminal.
当您有两个分支对同一个文件进行更改并尝试合并它们时,就会发生合并冲突。查看git status
终端上运行的冲突文件列表。
Conflicted lines of the files will be marked with visual indicators:
<<<<<
- The conflict starts after this line.
=====
- Devides changes from HEAD and merging_branch.
>>>>>
- End of the conflicted lines.
文件的冲突行将用视觉指示器进行标记:
<<<<<
- 冲突在此行之后开始。
=====
- 区分 HEAD 和 merging_branch 的更改。
>>>>>
- 冲突行的结尾。
<<<<<<< HEAD
conflicted text from HEAD
=======
conflicted text from merging_branch
>>>>>>> merging_branch
When you fix your conflicted files and you are ready to merge, all you have to do is run git add
and git commit
to generate the merge commit. Once the commit was made ,git push
the changes to the branch.
当您修复冲突文件并准备好合并时,您所要做的就是运行git add
并git commit
生成合并提交。提交后,git push
对分支的更改。
Reference article: Git merge.
参考文章:Git 合并。