我试图在GitHub上审查一个拉请求到一个不是主的分支。目标分支在master后面,拉请求显示了来自master的提交,所以我合并了master并将其推送到GitHub,但刷新后,他们的提交和差异仍然出现在拉请求中。我已经再次检查了GitHub上的分支是否有来自master的提交。为什么它们仍然出现在拉请求中?

我还检查了本地拉请求,它只显示未合并的提交。


当前回答

这里有一个很好的变通办法。在GitHub中查看PR时,使用Edit按钮将基本分支更改为master以外的内容。然后切换回master,现在它将正确地显示最近提交的更改。

其他回答

解决这个问题的一种方法是git在PR中rebase targetbranch。然后git push -force targetbranch,然后Github会显示正确的提交和diff。如果你不知道你在做什么,请小心使用这个。也许先签出一个测试分支来做rebase,然后git diff targetbranch以确保它仍然是你想要的。

看起来Pull Request没有跟踪目标分支的变化(我联系了GitHub支持,并在2014年11月18日收到了回复,说这是故意的)。

但是,你可以通过以下方法让它显示更新后的更改:

http://githuburl/org/repo/compare/targetbranch...currentbranch

根据需要替换githuburl, org, repo, targetbranch和currentbranch。

或者正如hexsprite在他的回答中所指出的,你也可以通过点击PR上的Edit来强制它进行更新,并临时将基础更改为不同的分支,然后再返回。这会产生警告:

你确定要改变底色吗? 类中的旧基本分支中的一些提交可能会被删除 时间轴,旧的评论可能会过时。

并将在PR中留下两个日志条目:

这发生在GitHub中,当你压缩从目标分支合并的提交时。

I had been using squash and merge with Github as the default merge strategy, including merges from the target branch. This introduces a new commit and GitHub doesn't recognize that this squashed commit is the same as the ones already in master (but with different hashes). Git handles it properly but you see all the changes again in GitHub, making it annoying to review. The solution is to do a regular merge of these pulled in upstream commits instead of a squash and merge. When you want to merge in another branch into yours as a dependency, git merge --squash and revert that single commit before pulling from master once that other branch has actually made it to master.

编辑:另一种解决方案是重新基底和强制推。干净但被改写的历史

用2点url代替3点url来比较

而不是

http://githuburl/org/repo/compare/targetbranch...currentbranch

Use

http://githuburl/org/repo/compare/targetbranch..currentbranch

综上所述,GitHub不会在拉请求中自动调整提交历史。最简单的解决方案是:

解决方案1:调整基数

假设你想从feature-01合并到master:

git fetch origin
git checkout feature-01
git rebase origin/master
git push --force-with-lease

如果你在一个分叉上工作,那么你可能需要用上游替换上面的原点。参见如何更新GitHub分叉存储库?了解有关跟踪原始存储库的远程分支的更多信息。

解决方案2:创建一个新的拉请求

假设你想从feature-01中合并介绍master:

git checkout feature-01
git checkout -b feature-01-rebased
git push -u origin feature-01-rebased

现在打开一个基于feature-01-re - based的拉请求,并关闭feature-01的拉请求。