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

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


当前回答

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

其他回答

在我回答之前先说说我的问题

我将考虑3个分支,主控、测试和特性。

测试分支已经有了主要的变化。

当我将master合并到我的特性分支中,然后工作并提交到我的特性分支中,当我提出一个针对测试的PR时,它会再次显示已经在测试中的更改。这令人沮丧,我的同事没有遇到这个问题,因为他们使用命令提示符。我不希望使用命令提示符。

我使用GitHub桌面应用程序,这种情况经常发生在我身上,直到今天我才对此无能为力。

如果你在你的特性分支上有无数次提交(最多4-5次),只有 那么这个程序就有用了。如果有的话,你可能会感到困惑 大量的提交。

现在围绕GitHub桌面用户的工作:

从测试创建一个分支,命名为“feature-merge-to-testing” 选择那些提交到“特性合并到测试”。 解决冲突。 现在针对测试分支提出一个PR。 一旦完成,删除“特性-合并-测试”分支。

直到GitHub修复桌面应用程序中PRs的问题。我想我要按这个程序来,这似乎对我很管用。如果有什么有效的工作,请告诉我。

改变底数(这个问题的第一个答案)对我没用。

我找到了一种方法来获得正确的行为(在2020年11月测试)。

git合并和解决冲突后,需要使用git merge——continue而不是git commit ....

使用git的精选

如果重基过程对您来说像对我一样混乱,另一个选择是使用git精选。以下是步骤:

Update your local target branch using git pull. checkout the branch where you made changes and copy the commit IDs of the commits you want. if the branch name is tangled, do git checkout tangled and then git log. You can scroll through the git log output using the up/down arrows on the keyboard. The commit IDs are the long numbers that each commit contains. Create a new branch from your target branch (e.g main) using git checkout -b new-branch-name when you are on the target branch. On the new branch, do git cherry-pick commit-id where commit-id is the long number that you copied from git log which identifies the commit you want to push. You can do this multiple times, changing the id each time to get another commit. If you run git log on this new branch which you created, you can see that only the changes you have added exist after your target branch's head, as expected. Lastly, push the changes to remote using git push origin new-branch-name and create a pull request.

解决这个问题的偷懒方式: 手动编辑分支中已经在目标分支中的文件,使用从目标分支的文件复制的相同代码,并保存它。它被提交。现在,PR将自动更新您所做的新提交,从而解决问题。

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

而不是

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

Use

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