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


当前回答

如果您使用GitHub Desktop,只需6步(实际上只有5步)即可轻松完成。

打开Github Desktop并选择存储库后,

转到“历史记录”选项卡单击搜索栏。它将显示所有可用的分支(包括父存储库的上游分支)选择相应的上游分支(它将是上游/主分支到同步主分支分支)(可选)它将显示上游分支中的所有提交。您可以单击任何提交都可以看到更改。根据您的活动分支,单击主/分支名称中的合并。等待GitHub Desktop发挥作用。

查看下面的GIF作为示例:

其他回答

从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

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

首先,检查遥控器/主机

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

GitHub现在引入了一个功能,可以通过单击按钮同步分叉。

转到您的分叉,单击“上游获取”,然后单击“获取并合并”以直接将分叉与其父回购同步。

您也可以单击“比较”按钮在合并之前比较更改。

参考:GitHub的文档

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