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


当前回答

如何在本地计算机上更新分叉回购?

首先,检查遥控器/主机

git remote -v

你应该有起点和上游。例如:

origin  https://github.com/your___name/kredis.git (fetch)
origin  https://github.com/your___name/kredis.git (push)
upstream    https://github.com/rails/kredis.git (fetch)
upstream    https://github.com/rails/kredis.git (push)

之后转到main:

git checkout main

并从上游合并到干管:

git merge upstream/main

其他回答

这取决于存储库的大小以及如何分叉。

如果它是一个很大的存储库,您可能希望以一种特殊的方式管理它(例如删除历史记录)。基本上,您可以获取当前版本和上游版本之间的差异,提交它们,然后将它们重新提交给master。

试试看这个。它描述了如何处理大型Git存储库,以及如何使用最新的更改对其进行上游处理。

我用这一行更新我的分叉回购:

git pull https://github.com/forkuser/forkedrepo.git branch

如果您不想在项目中添加另一个远程端点,请使用此选项,如其他解决方案所示。

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

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

如果你想让你的GitHub分叉与各自的上游保持最新,那么GitHub也有一个专门的probot程序:https://probot.github.io/apps/pull/这就完成了任务。您需要允许在您的帐户中安装,这将使您的叉子保持最新状态。

假设你的叉子是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>