我分叉了一个项目,进行了更改,并创建了一个被接受的拉取请求。新的提交后来被添加到存储库中。我怎样才能把这些承诺交给我?
当前回答
如果您设置了上游。用gitremote-v检查一下,这就足够了。
git fetch upstream
git checkout master
git merge --no-edit upstream/master
git push
其他回答
在分叉存储库的本地克隆中,可以将原始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 pull https://github.com/forkuser/forkedrepo.git branch
如果您不想在项目中添加另一个远程端点,请使用此选项,如其他解决方案所示。
GitHub现在引入了一个功能,可以通过单击按钮同步分叉。
转到您的分叉,单击“上游获取”,然后单击“获取并合并”以直接将分叉与其父回购同步。
您也可以单击“比较”按钮在合并之前比较更改。
参考:GitHub的文档
从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
如果您使用的是Windows或Mac的GitHub,那么现在他们有一个一键更新fork的功能:
在UI中选择存储库。单击顶部的“从用户/分支更新”按钮。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- 只用GitHub动作在特定分支上运行作业
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 是否有一个链接到GitHub下载文件的最新版本的存储库?