简体   繁体   English

在Github上推送请求

[英]Squashed Pull Request on Github

The Scenario: 场景:

  • Someone makes a pull request to my repo on github 有人向我在github上的仓库发出拉请求
  • I pulled the pull request locally to a feature branch 我在本地将拉取请求拉到功能分支
  • Rebased the branch and squashed all commits to a single good one 重新设置分支机构,并将所有提交压缩为一个良好的提交
  • Merged the feature branch using --no-ff to my master ("Merge pull request #5..") and push to origin 使用--no-ff将功能分支合并到我的主文件中(“合并拉取请求#5 ..”),然后推送到原点

The problem is Github does not recognize these rebase inside the pull request (which should be closed by now), rather obviously because of lost references. 问题是Github无法在pull请求(现在应该关闭)中识别出这些rebase,显然是因为丢失了引用。

What's the best practice in this case? 在这种情况下,最佳做法是什么? Especially if i don't want to force the contributor to manually squash his commits? 特别是如果我不想强迫贡献者手动压缩他的提交?

If I have understood/guessed right, all you're really wanting to do additionally is to tie the squashed merge commit more closely to the Pull Request, and close it automatically. 如果我理解/猜对了,那么您真正想要做的就是将压缩的合并提交与“拉取请求”更紧密地关联,并自动将其关闭。

The way I do this is to add "Closes #5" (Suggestion: as the first line) to the commit description in your Step 3 above. 我这样做的方法是在上述步骤3的提交描述中添加“ Closes#5”(建议:作为第一行)。 This will result in the PR being closed by the squashed commit and a reference added in the PR by GitHub. 这将导致PR被压缩的提交关闭,并且GitHub在PR中添加了引用。 Additionally, add a second "Closes #.." if you had an issue in your repository already which this PR closes too. 此外,如果您的存储库中存在此PR也将关闭的问题,则添加第二个“ Closes#..”。 Then both the issue and PR get closed with the same commit and GitHub will reference the squashed commit. 然后,问题和PR都将通过相同的提交关闭,并且GitHub将引用压缩的提交。

When doing this, I prefer to perform FF merges and hence have only one commit to the mainline per PR. 这样做时,我更喜欢执行FF合并,因此每个PR仅对主线执行一次提交。 I replace the default "Squashed commit of the following:" commit subject with one that actually describes what it's doing (eg "Adds feature to graph usage statistics"), then have the first lines of the commit description be the Closes # lines, and then put the Squashed commit details below that (assuming you want to keep those). 我将默认的“以下内容的压缩提交”替换为一个实际描述其行为的提交主题(例如“向图形使用统计信息添加功能”),然后使提交描述的第一行为“ Closes#”行,然后然后将“压缩提交”详细信息放在下面(假设您想保留这些详细信息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM