如何解决与 Git 的冲突?

How do I resolve conflicts with Git?

我有一个 pull request GitHub 告诉我 "This branch has conflicts that must be resolved." 我试过:

~/src/networkx: git rebase origin/master
Current branch topo is up to date.
~/src/networkx: git merge origin/master
Already up-to-date.

首先您需要确保您设置了上游远程存储库:

git remote add upstream git@github.com:networkx/networkx.git

然后您需要获取 upstream/master 并以此为基础进行变基。大致如下:

git fetch upstream
git checkout <feature-branch>
git rebase upstream/master

当 git 在 upstream/master 之上重放您的工作时,将会出现冲突,您将不得不深入研究文件以解决它们。那么你:

git add <files that you fixed>
git rebase --continue

试试运行这个看看你设置了什么遥控器:

git remote -v

如果您还没有您在 Github 中分叉的原始存储库的远程,您可以按如下方式添加它:

git remote add upstream https://github.com/networkx/networkx.git

这将命名远程上游。在此之后,您可以将最新的上游合并到您的分支并解决您的冲突:

git fetch upstream
git merge upstream/master

如果第一个 git remote -v 命令已经显示了具有该名称的遥控器,只需使用它而不是添加新的遥控器。希望对您有所帮助。

实际上...您不再需要在本地拉动和变基。
自 2016 年 12 月起,您可以通过 GitHub 解决(简单的)合并冲突。

参见“Resolve simple merge conflicts on GitHub

You can now resolve simple merge conflicts on GitHub right from your pull requests, saving you a trip to the command line and helping your team merge pull requests faster.

The new feature helps you resolve conflicts caused by competing line changes, like when people make different changes to the same line of the same file on different branches in your Git repository.
You'll still have to resolve other, more complicated conflicts locally on the command line.