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


当前回答

从github页面删除远程设备

然后应用这些命令:

1) git branch -D dev
2) git fetch upstream
3) git checkout master
4) git fetch upstream && git fetch upstream --prune && git rebase upstream/master && git push -f origin master
5) git checkout -b dev
6) git push origin dev
7) git fetch upstream && git fetch upstream --prune && git rebase upstream/dev && 8) git push -f origin dev

要查看配置,请使用以下命令:

git remote -v

其他回答

从github页面删除远程设备

然后应用这些命令:

1) git branch -D dev
2) git fetch upstream
3) git checkout master
4) git fetch upstream && git fetch upstream --prune && git rebase upstream/master && git push -f origin master
5) git checkout -b dev
6) git push origin dev
7) git fetch upstream && git fetch upstream --prune && git rebase upstream/dev && 8) git push -f origin dev

要查看配置,请使用以下命令:

git remote -v

自2013年11月以来,GitHub发布了一个非官方的功能请求,要求他们添加一个非常简单直观的方法来保持本地分叉与上游同步:

https://github.com/isaacs/github/issues/121

注意:由于功能请求是非官方的,因此建议联系support@github.com添加对要实现的类似功能的支持。上述非官方功能请求可作为对正在实施的功能感兴趣的证据。

截至本答复之日,GitHub在web界面中还没有(或者我应该说不再有?)这一功能。然而,你可以问support@github.com加上你的一票。

与此同时,GitHub用户bardiharborow创建了一个工具来实现这一点:https://upriver.github.io/

来源在这里:https://github.com/upriver/upriver.github.io

在分叉存储库的本地克隆中,可以将原始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即可。

以下是GitHub关于同步分叉的官方文档:

同步分叉设置在同步之前,需要添加指向上游存储库的远程。您可能在最初分叉时就这样做了。提示:同步fork只更新存储库的本地副本;它不会更新GitHub上的存储库。$git远程-v#列出当前遥控器起源https://github.com/user/repo.git(提取)起源https://github.com/user/repo.git(推)$git远程添加上游https://github.com/otheruser/repo.git#设置新遥控器$git远程-v#验证新远程起源https://github.com/user/repo.git(提取)起源https://github.com/user/repo.git(推)上游https://github.com/otheruser/repo.git(提取)上游https://github.com/otheruser/repo.git(推)正在同步将存储库与上游同步需要两个步骤:首先必须从远程获取,然后必须将所需的分支合并到本地分支。正在获取从远程存储库获取将带来其分支及其各自的提交。这些存储在本地存储库中的特殊分支下。$git获取上游#抓住上游遥控器的分支远程:计数对象:75,完成。远程:压缩对象:100%(53/53),完成。远程:总共62个(增量27),重复使用44个(增量9)拆包对象:100%(62/62),完成。从…起https://github.com/otheruser/repo*[新分支]主->上游/主现在,上游的主分支存储在本地分支上游/主分支中$git分支-va#列出所有本地和远程跟踪分支*master a422352我的本地提交remotes/origin/HEAD->origin/masterremotes/origin/master a422352我的本地提交remotes/upstream/master 5fdff0f一些上游提交合并现在我们已经获取了上游存储库,我们希望将其更改合并到本地分支中。这将使该分支与上游同步,而不会丢失本地更改。$git结帐主机#查看我们当地的主分支机构切换到分支“主”$git合并上游/主#将上游的主机合并到我们自己的主机中正在更新a422352..5fdff0f快进自述文件|9-------阅读.md | 7++++++2个文件已更改,7个插入(+),9个删除(-)删除模式100644 README创建模式100644 README.md如果您的本地分支没有任何唯一的提交,git将执行“快进”:$git合并上游/主正在更新34e91da。。16c56天快进阅读.md | 5+++--1个文件已更改,3个插入(+),2个删除(-)提示:如果您想更新GitHub上的存储库,请按照此处的说明进行操作