我试图在GitHub上审查一个拉请求到一个不是主的分支。目标分支在master后面,拉请求显示了来自master的提交,所以我合并了master并将其推送到GitHub,但刷新后,他们的提交和差异仍然出现在拉请求中。我已经再次检查了GitHub上的分支是否有来自master的提交。为什么它们仍然出现在拉请求中?
我还检查了本地拉请求,它只显示未合并的提交。
我试图在GitHub上审查一个拉请求到一个不是主的分支。目标分支在master后面,拉请求显示了来自master的提交,所以我合并了master并将其推送到GitHub,但刷新后,他们的提交和差异仍然出现在拉请求中。我已经再次检查了GitHub上的分支是否有来自master的提交。为什么它们仍然出现在拉请求中?
我还检查了本地拉请求,它只显示未合并的提交。
当前回答
使用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.
其他回答
您需要在~/中添加以下内容。gitconfig文件:
[rebase]
autosquash = true
这将自动实现与此答案所显示的相同的结果。
接下来我来处理。
用2点url代替3点url来比较
而不是
http://githuburl/org/repo/compare/targetbranch...currentbranch
Use
http://githuburl/org/repo/compare/targetbranch..currentbranch
我不太确定这背后的理论。但我得到了这个几次,并能够通过做下面的事情来解决这个问题。
git pull --rebase
这将从您的原始回购主分支获取并合并更改(如果您有指向)
然后你把你的更改强行推到你的github克隆库(目标)
git push -f origin master
这将确保你的github克隆和你的父repo在相同的github提交级别,你不会看到跨分支的任何不必要的更改。
综上所述,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的拉请求。
这里有一个很好的变通办法。在GitHub中查看PR时,使用Edit按钮将基本分支更改为master以外的内容。然后切换回master,现在它将正确地显示最近提交的更改。