git “此拉取请求包含必须解决的合并冲突。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26241428/
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
"This pull request contains merge conflicts that must be resolved."
提问by Nathan
I'm getting that error with a PR, but when I git status
it says nothing to commit, working directory clean
.
我在 PR 中遇到了那个错误,但是当我git status
说nothing to commit, working directory clean
.
That's on the branch with the PR.
那是在 PR 的分支上。
On branch pr12
nothing to commit, working directory clean
回答by Peeja
git status
tells you about the state of your working directory treeand your index(where staged changes live) relative to the latest commit on the current branch. The output you're seeing means that the files on your disk exactly match the latest commit on your branch. That is, there's "nothing to commit".
git status
告诉你你的工作目录树的状态和你的索引(其中暂存更改的位置)相对于当前分支上的最新提交。您看到的输出意味着磁盘上的文件与分支上的最新提交完全匹配。也就是说,没有什么可提交的。
The message from GitHub is not about committing, but about merging. GitHub would like to offer you a one-click method to merge this branch into your master
branch, but it can't, because that merge results in conflicts. Since GitHub doesn't have a way to help you resolve conflicts though the website, it asks you to resolve them on your own machine.
来自 GitHub 的信息不是关于提交,而是关于合并。GitHub 想为您提供一种一键式方法来将此分支合并到您的master
分支中,但它不能,因为合并会导致冲突。由于 GitHub 没有办法通过网站帮助您解决冲突,因此它要求您在自己的机器上解决它们。
The best way to deal with this situation is to merge the current master branch into your topic branch locallyand then push the result to GitHub. To do that, do the following:
处理这种情况最好的办法是将当前的master分支在本地合并到你的topic分支,然后将结果推送到GitHub。为此,请执行以下操作:
$ git checkout pr12 # If you're not already on pr12
$ git fetch origin
$ git merge origin/master
(I'm assuming that the GitHub remote is called origin
. It typically is, and you probably know if it isn't.)
(我假设 GitHub 远程被称为origin
。它通常是,如果不是,您可能知道。)
First we make sure we're on the right branch. Then we make sure we have the latest code from the master
branch on the GitHub repo. Then we merge that code into our pr12
branch.
首先,我们确保我们在正确的分支上。然后我们确保我们有来自master
GitHub 存储库上的分支的最新代码。然后我们将该代码合并到我们的pr12
分支中。
Remember: git fetch origin
updates our local origin/master
to be the same as GitHub's master
, but it doesn't touch the local branch called simply master
. We'd have to checkout our master
branch to make changes to it. Instead, we just update our idea of what's on GitHub (origin/master
) and merge that into our pr12
.
请记住:将git fetch origin
我们的本地更新origin/master
为与 GitHub 的 相同master
,但它不会触及名为 simple 的本地分支master
。我们必须检查我们的master
分支才能对其进行更改。相反,我们只是更新我们对 GitHub ( origin/master
)上内容的想法并将其合并到我们的pr12
.
When you run the merge
command, you'll see conflicts. Those represent decisions that git (and GitHub) couldn't make automatically. Edit those files so they're the way you want them to end up. Then:
当您运行该merge
命令时,您会看到冲突。这些代表了 git(和 GitHub)无法自动做出的决定。编辑这些文件,使其成为您希望它们最终的样子。然后:
$ git add each/file.txt that/had/conflicts.conf
$ git commit # Your editor will open with a pre-filled
# commit message. Just save and close the file.
$ git push origin pr12
That is, we add the versions of the files that we fixed, then finish the merge commit we started with git merge
. Lastly, we push the branch with the new merge commit up to GitHub.
也就是说,我们添加我们修复的文件的版本,然后完成我们开始的合并提交git merge
。最后,我们将带有新合并提交的分支推送到 GitHub。
Since we've resolved the conflicts, this branch should be trivial to merge the other way, into master
. GitHub will notice that, and give you a green "Merge" button.
由于我们已经解决了冲突,这个分支应该很容易以另一种方式合并到master
. GitHub 会注意到这一点,并为您提供一个绿色的“合并”按钮。
回答by LondonRob
When I encountered this message, it was because my forkof a particular repo was behind the original. In my particular case the repo I'd forked is pydata/pandas
.
当我遇到这条消息时,是因为我对特定 repo 的fork落后于原始 repo。在我的特殊情况下,我分叉的回购是pydata/pandas
.
I had to configure a remote for my forkby doing:
我必须通过执行以下操作为我的叉子配置一个遥控器:
> git remote add upstream [email protected]:original_user/original_repo.git
> git remote -v
origin [email protected]:some_user/pandas.git (fetch)
origin [email protected]:some_user/pandas.git (push)
upstream [email protected]:pydata/pandas.git (fetch)
upstream [email protected]:pydata/pandas.git (push)
(Note: git remote add upstream
is a git's way of saying "Add a remote called "upstream". The name can be anything.)
(注意:git remote add upstream
是 git 的说法“添加名为“上游”的遥控器。名称可以是任何内容。)
Then I fetched the latest commitsfrom the original repo with:
然后我从原始 repo 中获取了最新的提交:
> git fetch upstream
> git checkout master # Just in case you're not already on master
> git merge upstream/master
and finally push the merged repo back to github:
最后将合并的 repo 推送回 github:
> git push