git GitHub“无法自动合并”?

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

GitHub "can't automatically merge"?

gitgithubmerge

提问by user2568374

Sometimes when i try to merge the head fork into my base fork, or my base fork into the head fork, I get the following message on GitHub:

有时,当我尝试将头叉合并到我的基础叉中,或将基础叉合并到头叉中时,我会在 GitHub 上收到以下消息:

"Can't automatically merge. Don't worry, you can still create the pull request."

“无法自动合并。别担心,你仍然可以创建拉取请求。”

How do I view the conflicts, if there are any for this?

如果有任何冲突,我如何查看冲突?

I have read about 10 different examples with various commands but I can't tell what the names in the examples apply to in my situation as different names for bases, forks, branches, etc, exist.

我已经阅读了大约 10 个带有各种命令的不同示例,但是我无法说出示例中的名称在我的情况下适用于什么,因为存在不同的基础、分叉、分支等名称。

After all of this, I can't believe there isn't a command you can type to see the conflicts, edit the conflicts and go on with merging. If there is, I haven't found it yet.

毕竟,我不敢相信没有您可以键入的命令来查看冲突、编辑冲突并继续合并。如果有,我还没有找到。

回答by Thomas Stringer

That means that your pull request can't be merged into the upstream without the upstream owner(s) having to resolve merge conflicts.

这意味着您的拉取请求不能在没有上游所有者必须解决合并冲突的情况下合并到上游。

The resolution here would be for you to do a fetch from the upstream and then resolve the merge conflicts from the upstream. At this point, if you theoretically resolve the conflicts from the upstream and then create your pull request, upstream would be able to automatically merge in your pull request without having any conflicts (provided there were no commits on the upstream between you locally resolving the upstream merge conflicts and merging into your local/fork, and then creating the pull request).

这里的解决方案是让您从上游获取数据,然后从上游解决合并冲突。此时,如果您从理论上解决了上游的冲突,然后创建了您的拉取请求,上游将能够自动合并您的拉取请求而不会产生任何冲突(前提是您在本地解决上游的上游没有提交合并冲突并合并到您的本地/分支,然后创建拉取请求)。

Let's use GitHub as an example here for remote repo store.

让我们在这里使用 GitHub 作为远程存储库的示例。

OriginalAccount\repo1- say this is the original repository (we will refer to this as "upstream")

OriginalAccount\repo1- 说这是原始存储库(我们将其称为“上游”)

YourAccount\repo1- this would be your fork of the repository (this is typically the "origin" remote)

YourAccount\repo1- 这将是您的存储库的分支(这通常是“源”远程)

repo1local- this is your local copy of the repository.

repo1 local- 这是存储库的本地副本。

When you create a pull request from YourAccount\repo1to OriginalAccount\repo1(virtually from originto upstream), seeing the message that you can't merge automatically means that OriginalAccount\repo1has commits that YourAccount\repo1doesn't have (commits that were most likely pushed after you forked).

当您创建从YourAccount\repo1OriginalAccount\repo1(实际上是从originupstream)的拉取请求时,看到您无法自动合并的消息意味着OriginalAccount\repo1具有YourAccount\repo1没有的提交(提交很可能在您分叉后被推送)。

The solution here would be to fetch from upstreamto your local repository (from OriginalAccount\repo1to your local repo) and resolve any merge conflicts locally. Then push your commits to YourAccount\repo1. At this point, you should be able to create your pull request that should be able to be automatically merged into OriginalAccount\repo1.

这里的解决方案是从上游获取到您的本地存储库(从OriginalAccount\repo1到您的本地存储库)并在本地解决任何合并冲突。然后将您的提交推送到YourAccount\repo1。此时,您应该能够创建您的拉取请求,该请求应该能够自动合并到OriginalAccount\repo1 中

Note: Even though most Git services won't prevent you from continuing on with a pull request that requires the upstream contributors to resolve merge conflicts, it is good practice and good etiquette to ensure that your pull request merges with no conflict. Think about it like this, you should be doing the merge conflict resolution work, instead of having the upstream contributors doing that work from your contribution.

注意:尽管大多数 Git 服务不会阻止您继续执行需要上游贡献者解决合并冲突的拉取请求,但确保您的拉取请求合并时没有冲突是一种很好的做法和良好的礼仪。这样想,你应该做合并冲突解决工作,而不是让上游贡献者从你的贡献中做这项工作。

回答by aaa bbb

Let's say there is your-branch and the master branch. You want to merge changes from your-branch into the master for others to see them, but someone else did conflicting changes to the master (e.g. merging their PR) in the meantime. It is often useful to merge master into your-branch (i.e. do the merge the other way round) before creating the PR.

假设有 your-branch 和 master 分支。您想将您的分支中的更改合并到 master 中以供其他人查看,但在此期间其他人对 master 进行了相互冲突的更改(例如合并他们的 PR)。在创建 PR 之前将 master 合并到你的分支(即以相反的方式进行合并)通常很有用。

In the command line, you can:

在命令行中,您可以:

git checkout master
git pull
git checkout your-branch
git merge master

Now you can see the list of conflicts. Follow the messages you get from git to resolve the conflicts. You can use your favorite tools, so it is way easier. Finally, you commit&push. When you re-create the PR, there should be no conflicts.

现在您可以看到冲突列表。按照您从 git 获得的消息解决冲突。您可以使用自己喜欢的工具,这样就简单多了。最后,您提交并推送。当您重新创建 PR 时,应该没有冲突。

回答by user2568374

The easy way to do this is to use Github this way:

做到这一点的简单方法是这样使用 Github:

  • In Github select branches tab, click merge view button, drag your head fork to the left box, drag your base fork to the right box.
  • Click MergeBranches button.
  • Select changestab.
  • Select each file that has conflicts. see '<<<<<<<' Edit files in external viewer to keep headfork code and add yours to it.
  • Click Saveon file(s).
  • Click Committo button.
  • Click sync.
  • Go to Gitwebsite and try merging your base fork to head fork again.
  • 在 Github 中选择分支选项卡,单击合并视图按钮,将您的头叉拖到左侧框,将您的基础叉拖到右侧框。
  • 单击合并分支按钮。
  • 选择更改选项卡。
  • 选择每个有冲突的文件。请参阅“ <<<<<<<”在外部查看器中编辑文件以保留头叉代码并将您的代码添加到其中。
  • 单击保存在文件上。
  • 单击“提交到”按钮。
  • 单击同步。
  • 转到Git网站并再次尝试将您的基础叉合并到头叉。

It should no longer show the original message

它不应再显示原始消息

回答by Ben

You get conflicts when your code being merged into the repo will conflict with the code already there. If your pull request is accepted, it will be up to the repo manager to resolve them.

当您的代码被合并到 repo 中时会与已经存在的代码发生冲突,您会遇到冲突。如果您的拉取请求被接受,则由回购经理来解决它们。