繁体   English   中英

使用交互式变基压缩时,Git 跳过合并提交

[英]Git skips merge commit when squashing using interactive rebase

我正在使用 git 开发一个功能,到目前为止我已经完成了以下步骤。

  • 基于master结帐名为feature1的新功能分支
  • 添加几个提交。
  • 基于feature1签出新的分支test
  • test执行一些更改。
  • 返回(结帐到) feature1分支。
  • test分支合并到feature1
  • 删除test分支
  • 编辑文件,并修改最后一次提交以反映更改

这是git log --oneline -n 5输出

de5d701 Merge branch 'test' into 'feature1' (amended)
a668f93 'feature1' commit3
ded7c00 'feature1' commit2
8731807 Initial 'feature1' commit
ff2f539 latest 'master' commit

我想在合并到master之前ff2f539 latest 'master' commit之后的所有内容。 我试着表演

git rebase --interactive  ff2f539

但最新的提交未在编辑器中列出:

pick 8731807 Initial 'feature1' commit
pick ded7c00 'feature1' commit2
pick a668f93 'feature1' commit3

# Rebase ff2f539..de5d701 onto ff2f539
#
# Commands:
...
# Note that empty commits are commented out

我不明白为什么跳过由合并test分支到feature1分支产生的最新提交。 保存并退出编辑器,内容如下:

pick 8731807 Initial 'feature1' commit
squash ded7c00 'feature1' commit2
squash a668f93 'feature1' commit3

# Rebase ff2f539..de5d701 onto ff2f539
#
# Commands:
...
# Note that empty commits are commented out

生成不提供上次提交更改的新提交

de5d701 Merge branch 'test' into feature1(amended)

他们失去了。 在合并到 master 之前如何将所有这些提交压缩为一个单一提交有什么帮助吗?

Git 按照设计不会在“交互式”列表中显示合并提交。 相反,它包括由该合并带入分支的所有提交。 您可以使用-p ( --preserve-merges ) 选项来更改该行为,但不建议在交互模式下使用,因为结果可能不那么明显(请参阅http://git-scm.com/docs/git -rebase#_bugs )。

但是有一个简单的解决方案,无需重新定位:

# make sure your working copy is clean, do git stash if needed
git checkout feature1
git reset --soft ff2f539
git commit -m "..."

这将产生一个提交,包括 ff2f539 之后的所有更改。

如果要在 rebase 中包含合并提交,请将--preserve-merges选项传递给git rebase

暂无
暂无

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

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