为github pull请求只压缩一次"正确"提交

Cho*_*ett 46 git github pull-request

我在github上有一个回购,其他人(Bob,为了争论)发出了拉请求.他的代码不完美,所以我们经历了几轮标记.据我了解,他承诺并推动他对每组标记变更的拉动请求.

所以我的存储库现在看起来像这样:

master: ---o A (Chowlett
           |
           |
pull-req:  o---o---o---o
               B   C   D (all Bob)
Run Code Online (Sandbox Code Playgroud)

提交SHA和消息如下:

A:

123456 Good commit <chowlett>
Run Code Online (Sandbox Code Playgroud)

B:

777ccc Fix the widget bug <bob>
Run Code Online (Sandbox Code Playgroud)

C:

888ddd Review markups <bob>
Run Code Online (Sandbox Code Playgroud)

d:

999eee Further markups <bob>
Run Code Online (Sandbox Code Playgroud)

我现在很高兴接受这个拉动请求; 但我宁愿预标记版本不在我的回购中.我可以实现以下所有目标吗?如何?

  • 将B,C&D合并为我的仓库作为单个提交
  • 生成"合并拉取请求#99到..."提交
  • 让github自动关闭拉取请求

Von*_*onC 17

请注意,Bob在制作GitHub PR时不必压缩他的提交.
自2016年3月起,您可以将该操作留给维护者(您)接受您的PR.

请参阅" 压缩您的提交 "及其新文档

这是一个新选项,允许您强制提交压缩通过合并按钮合并的所有拉取请求.

https://help.github.com/assets/images/help/pull_requests/squash-and-merge.png


joe*_*eln 10

内置了两个"壁球"功能git.有,git merge --squash并且有squash行动git rebase --interactive.前者不保留任何作者或日期信息,只是将一系列提交中的所有更改收集到本地工作副本中.后者很烦人,因为它需要互动.

git squash扩展你想要做什么.它将当前HEAD重新绑定到指定的基础上,同时自动压缩其间的提交.它还提供了一个命令行选项,用于在rebase不会产生冲突的情况下在最终压缩的提交上设置消息.

连同引发此hubghi,你也许能够沿着这些路线构建脚本:

git pull upstream master
hub checkout https://github.com/$user/$repo/pull/$issue
git squash master
rev=$(git rev-parse --short HEAD)
git checkout master
git merge $rev
git commit --amend "Merged pull request #$issue"
git push upstream master
ghi close $issue $user/$repo
ghi comment $issue "Merged as $rev" $user/$repo 
Run Code Online (Sandbox Code Playgroud)


D-R*_*ock 9

您可以使用--squash选项进行合并

git merge <remote url> <remote branch> --squash
Run Code Online (Sandbox Code Playgroud)

但是,这不会产生合并提交.它将生成一组正常的工作树更改,就像您手动将所有更改应用于副本一样.然后你会像平常那样提交.

缺点是您在master上的历史记录不会将此提交显示为来自其分支的合并.它看起来就像你自己做了工作而不是给鲍勃一样.