我分叉了一个项目,进行了更改,并创建了一个被接受的拉取请求。新的提交后来被添加到存储库中。我怎样才能把这些承诺交给我?


当前回答

假设你的叉子是https://github.com/me/foobar原始存储库是https://github.com/someone/foobar

参观https://github.com/me/foobar/compare/master...someone:master如果您看到绿色文本“能够合并”,请按Create pull request在下一页上,滚动到页面底部,然后单击合并请求和确认合并。

使用以下代码段生成链接以同步分叉存储库:

新Vue({el:“#app”,数据:{yourFork:'https://github.com/me/foobar',原始回购:'https://github.com/someone/foobar'},计算:{syncLink:函数(){const yourFork=新URL(this.yourFork).pathname.split('/')const originalRepo=新URL(this.originalRepo).pathname.split('/')如果(yourFork[1]&&yourFork[2]&&originalRepo[1]){返回`https://github.com/${yourFork[1]}/${yourFork[2]}/compare/master${originalRepo[1]}:主`}return“数据不足”}}})<script src=“https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js“></script><div id=“app”>您的分叉URL:<inputsize=50v-model=“yourFork”/><br/>原始存储库URL:<input v-model=“originalRepo”size=50/><br/>用于同步分叉的链接:<a:href=“syncLink”>{syncLink}</a></div>

其他回答

在分叉存储库的本地克隆中,可以将原始GitHub存储库添加为“远程”。(“Remotes”就像是存储库URL的昵称,例如,origin就是其中之一。)然后,您可以从上游存储库中获取所有分支,并重新设置工作基础,继续使用上游版本。就命令而言,可能如下所示:

# Add the remote, call it "upstream":

git remote add upstream https://github.com/whoever/whatever.git

# Fetch all the branches of that remote into remote-tracking branches

git fetch upstream

# Make sure that you're on your master branch:

git checkout master

# Rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:

git rebase upstream/master

如果您不想重写主分支的历史记录(例如,因为其他人可能已经克隆了它),那么应该用gitmergeupstream/master替换最后一个命令。然而,为了做出尽可能干净的进一步拉取请求,可能最好重新设置基址。


如果您已经将分支重新基于upstream/master,则可能需要强制推送,以便将其推送到GitHub上自己的分叉存储库。你可以这样做:

git push -f origin master

您只需要在重新启动后第一次使用-f即可。

使用这些命令(在幸运的情况下)

git remote -v
git pull
git fetch upstream
git checkout master
git merge upstream/master --no-ff
git add .
git commit -m"Sync with upstream repository."
git push -v

如果您设置了上游。用gitremote-v检查一下,这就足够了。

git fetch upstream
git checkout master
git merge --no-edit upstream/master
git push

许多答案最终会将fork移到父存储库之前一次提交。这个答案总结了这里找到的步骤,这些步骤会将您的fork移动到与父级相同的提交。

将目录更改为本地存储库。如果您不是git结账主管,请切换到master分支将父级添加为远程存储库,git remote Add upstream<repo location>向上游发出git fetch发布git上游/主数据库在这个阶段,您可以通过键入gitstatus来检查提交将要合并的内容发布git推送源主机

有关这些命令的更多信息,请参阅步骤3。

如果像我一样,你从来没有直接向主人承诺过什么,你真的应该这样做,你可以做以下事情。

从fork的本地克隆创建上游远程。你只需要做一次:

git remote add upstream https://github.com/whoever/whatever.git

然后,每当您想赶上上游存储库主分支时,您需要:

git checkout master
git pull upstream master

假设你从未对师父做过任何事,你应该已经做了。现在,您可以将本地主机推送到源远程GitHub分叉。您还可以将开发分支重新基于当前最新的本地主机。

在初始的上游设置和主签出之后,您需要做的就是运行以下命令以将主设备与上游设备同步:git pull上游主设备。