合并冲突 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10369701/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:51:19  来源:igfitidea点击:

Merge conflict Git

gitegit

提问by Duc Le

I and my friend fork from the main repository (upstream). Last night, we had the same version of this repository in local machine. Then I have added a new feature and my friend also added another new feature too. My friend pulled request to the main repository and I have merge this pull request with the upstream repository with no conflict. And when I fetch from upstream and merge with my master branch, it conflicts. What should I do in this situation to resolve conflict? (The upstream repository should have 2 new features after resolving conflict)

我和我的朋友从主存储库(上游)分叉。昨晚,我们在本地机器上有这个存储库的相同版本。然后我添加了一个新功能,我的朋友也添加了另一个新功能。我的朋友向主存储库拉取请求,我已将此拉取请求与上游存储库合并,没有冲突。当我从上游获取并与我的主分支合并时,它会发生冲突。在这种情况下我应该怎么做才能解决冲突?(解决冲突后,上游存储库应该有2个新功能)

采纳答案by Dougal

Just go through the files marked as conflicted by git statusand find the conflict markers (you can search for ====in the file). Reconcile the changes between them, figure out if anything else unexpected got broken by the combination of your code, run your tests, and then use git addand git commitas normal to make a commit merging your friend's new feature with yours.

只需浏览标记为冲突的文件git status并找到冲突标记(您可以====在文件中搜索)。协调它们之间的更改,弄清楚您的代码组合是否破坏了其他任何意想不到的东西,运行您的测试,然后像往常一样使用git addgit commit进行提交,将您朋友的新功能与您的新功能合并。

Upstream: original                 with friend's feature            with both
               \  \               /                \               /
                \  -- Friend's --/                  \             /
                 \                                   \           /
                  ---- Yours ------------------------- your merge

回答by VonC

Note that you can also solve directly a merge conflict from Eclipse/Egit itself:
See "Egit: Solving Merge Conflicts":

请注意,您也可以直接从 Eclipse/Egit 本身解决合并冲突
请参阅“ Egit:解决合并冲突”:

You can manually edit the text on the left side or use the Copy current change from right to left button to copy the conflicting changes from right to left.

Next step is from the context menu of the file, to select Team -> Add to index. Than commit.

您可以手动编辑左侧的文本或使用从右向左复制当前更改按钮从右向左复制冲突的更改。

下一步是从文件的上下文菜单中,选择 Team -> Add to index。比提交。

merge conflict resolution in EGit

在 EGit 中合并冲突解决

回答by xeorem

You can type git difftool path/filenamein the console to use a tool to resolve the conflict or use Git software that has conflict resolution built in. I really like SmartGit (from the makers of SmartSVN) and TortoiseGit (very similar to TortoiseSVN).

你可以git difftool path/filename在控制台输入使用工具解决冲突,或者使用内置冲突解决的Git软件。我非常喜欢SmartGit(来自SmartSVN的制造商)和TortoiseGit(非常类似于TortoiseSVN)。