简体   繁体   English

如何合并有冲突的存储库?

[英]How to merge repositories with conflicts?

I am very new to git / GitHub, and frequently get confused. 我对git / GitHub非常陌生,经常感到困惑。 What I am specifically confused about is how to combine two repositories with merge conflicts. 我特别困惑的是如何结合合并冲突来合并两个存储库。

So, there is a base repository by a colleague that I forked, say his name is Frank, so I forked frank/master into me/master . 因此,有一个我分叉的同事的基础存储库,说他的名字叫Frank,所以我把frank/master分叉到me/master Now I made changes, and Frank made changes, so that now me/master is 10 commits ahead and 20 commits behind frank/master . 现在,我进行了更改,而Frank进行了更改,因此me/master现在领先10提交,而frank/master之后落后20提交。

Now, I want to merge the repositories back together. 现在,我想将存储库重新合并在一起。 However, me and Frank both edited the same files, which means that a pull request can't be automatically merged. 但是,我和Frank都编辑了相同的文件,这意味着拉取请求无法自动合并。

I thought the easiest way to resolve this would be to make a new branch on GitHub (which I did), called devel , and to pull frank/master . 我认为解决此问题的最简单方法是在GitHub上创建一个名为devel的新分支(我做过),并拉frank/master I opened a pull request on GitHub, and then followed the command line instructions to resolve the conflicts: 我在GitHub上打开了请求请求,然后按照命令行说明解决冲突:

git checkout -b frank-master devel
git pull https://github.com/frank/theRepositor.git master

Then I used git mergetool to resolve the conflicts in meld (and edited the middle document), and then did 然后,我使用git mergetool解决了git mergetool中的冲突(并编辑了中间文档),然后执行了

git checkout devel
git merge --no-ff frank-master
git push origin devel

Now the Github page says that my devel repository is 20 commits behind and 11 commits ahead of frank/master, but the pull request is still open and can't be resolved. 现在,Github页面上说我的开发仓库在frank / master之后落后了20个提交,而11个则领先于frank / master,但是pull请求仍然处于打开状态,无法解决。

What did I do wrong and what is the correct workflow to resolve such conflicts and merge repositories back together? 我做错了什么?解决此类冲突并将存储库重新合并在一起的正确工作流程是什么?

You can resolve simple merge conflicts, like the one you are describing, in the GitHub web UI. 您可以在GitHub Web UI中解决简单的合并冲突,如您所描述的。 Check out this article: https://help.github.com/articles/resolving-a-merge-conflict-on-github/ 查看本文: https : //help.github.com/articles/resolving-a-merge-conflict-on-github/

If a merge conflict has occurred because there's a difference on the same line of the same file between the two branches of your pull request, you can now hit the Resolve conflicts button, found in in the body of the pull request. 如果由于合并请求的两个分支之间在同一文件的同一行上存在差异而发生了合并冲突,那么您现在可以单击位于合并请求主体中的“ 解决冲突”按钮。 This will launch a text editor where you can resolve the issue. 这将启动一个文本编辑器,您可以在其中解决问题。 All other types of merge conflicts must be resolved locally on the command line . 所有其他类型的合并冲突必须在命令行上本地解决

When resolving a merge conflict, you can choose to keep the content from one of your branches or make a brand new change. 解决合并冲突时,您可以选择保留分支机构之一中的内容或进行全新的更改。 Simply find and remove conflict markers ( <<<<< , ===== , >>>>> ), make your changes, hit the Mark as resolved button, and then the Commit changes button. 只需查找并删除冲突标记( <<<<<=====>>>>> ),进行更改,单击“ 标记为已解决”按钮,然后单击“ 提交更改”按钮。 When you have resolved all merge conflicts, the Merge pull request button will turn green, meaning you can merge your changes. 解决所有合并冲突后,“ 合并”拉取请求按钮将变为绿色,这意味着您可以合并更改。 This assumes any required status checks pass and that you have permission to merge to that branch. 这假定通过了所有必需的状态检查,并且您有权合并到该分支。

To learn more, visit the GitHub Help article on merge conflicts: https://help.github.com/articles/about-merge-conflicts/ 要了解更多信息,请访问关于合并冲突的GitHub帮助文章: https : //help.github.com/articles/about-merge-conflicts/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM