git - 为github上的项目做贡献,如何 "rebase my pull request on top of master"

标签 git github

好的,我正在为 github 上的一个项目做贡献。 github上的项目是upstream,我在github上的fork repo是origin,我的local repo在我的电脑上。

git checkout -b feature
# Working on feature
git commit -a -m 'only commit on feature'

然后我提交一个 pull 请求

git push origin master

pull 请求已审核,需要进行不相关的更改。其他人提交并 merge 到 upstream/master

现在 upstream 维护者要求我“将我的 pull request 重新设置在 master 之上”

这是我的故事(插入法律与秩序音效)......

我没有对 pull 请求进行任何更改,它仍然是相同的分支提交功能。

git checkout master
git fetch upstream
git checkout feature
git rebase master
=> "Current branch feature is up to date."
git push origin feature
=> "Everything up-to-date"

我不明白。当我将 pull 请求推送到 origin/feature 后,我知道有人提交并 merge 到 upstream/master 时,这怎么可能?

谁能告诉我在这种情况下正确的程序应该是什么?

最佳答案

您只在上游存储库中显示抓取。这实际上并没有更新您的任何本地分支机构。它only updates your knowledge of upstream .在 rebase 到 之前,您需要确保 upstream/master 已完全 merge 到您的 master 中,就像使用 git pull 一样master,或者更简单地只是 rebase 到 upstream/master

即:

git checkout master
git pull upstream master
git checkout feature
git rebase master

git checkout feature
git fetch upstream master
git rebase upstream/master

更新:

修复本地 feature 分支后,您需要将其推回到 origin 以完成更新 pull 请求。由于您已经推送了一次 feature,您不能简单地再次 push,因为 rebase 改变了历史,而且它不再是快进。通常,当推送因“非快进”而失败时,您可以通过 pull 来解决它,但是 pull 只会结合两个不同的历史记录,这绝对不是您想要的。这意味着您的旧(rebase 前)feature 分支将与新的(rebase 后)分支 merge 。您想用新的 feature 分支的状态覆盖 origin/feature,转储旧分支的所有记录。这意味着您需要使用 git push -f origin feature 强制推送,即使它不是快进。注意:强制推送是危险的,你可能会丢失提交。仅当您绝对确定自己知道自己在做什么时才使用它,就像在这里,您有意要将旧的、无用的提交放在 pre-rebase feature 分支中。

关于git - 为github上的项目做贡献,如何 "rebase my pull request on top of master",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17182624/

相关文章:

git - 推送到gitlab时要求输入密码?

git:如何压缩多个 merge 提交

git - 通过 git 自动将 Assets 部署到 Rackspace CDN 并更新对这些 Assets 的引用?

ios - Git 推送本地 PodSpec

windows - 为什么 npm install 在 Windows cmd 中运行时失败,但在从 git bash 或 vs 终端运行时工作正常?

git - 如何使用 Ubuntu (systemd)、Github 和 SSH key 在启动时从 git 中提取

git - 在提交到 master 后如何撤销所做的更改?

windows - 通过 Github 桌面应用程序(Windows)推送到 Github 的提交未显示

windows - 如何从 GitHub for windows 隐藏已删除的文件

Windows定时任务git push到github