[英]Git skips merge commit when squashing using interactive rebase
I am working on a feature using git and I have the following steps completed so far.我正在使用 git 开发一个功能,到目前为止我已经完成了以下步骤。
feature1
based on master
基于master
结帐名为feature1
的新功能分支test
based on feature1
.基于feature1
签出新的分支test
。test
.在test
执行一些更改。feature1
branch.返回(结帐到) feature1
分支。test
branch to feature1
将test
分支合并到feature1
test
branch删除test
分支Here is git log --oneline -n 5
output这是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
I want to squash everything which comes after ff2f539 latest 'master' commit
before merging to master
.我想在合并到master
之前ff2f539 latest 'master' commit
之后的所有内容。 I tried to perform我试着表演
git rebase --interactive ff2f539
but the latest commit is not listed in the editor:但最新的提交未在编辑器中列出:
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
I can not understand why the latest commit which is produced by the merging of test
branch to feature1
branch is skipped.我不明白为什么跳过由合并test
分支到feature1
分支产生的最新提交。 Saving and exiting the editor with the following content:保存并退出编辑器,内容如下:
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
produces new commit which does not provide the changes from the last commit生成不提供上次提交更改的新提交
de5d701 Merge branch 'test' into feature1(amended)
They are lost.他们失去了。 Any help how to squash all those commits into one single commit before merging to master ?在合并到 master 之前如何将所有这些提交压缩为一个单一提交有什么帮助吗?
Git does not show merge commits in the "interactive" list by design. Git 按照设计不会在“交互式”列表中显示合并提交。 It instead includes all commits that were brought into the branch by that merge.相反,它包括由该合并带入分支的所有提交。 You can use -p
( --preserve-merges
) option to change that behavior, but it is not recommended in interactive mode, because the result may be not that obvious (see http://git-scm.com/docs/git-rebase#_bugs ).您可以使用-p
( --preserve-merges
) 选项来更改该行为,但不建议在交互模式下使用,因为结果可能不那么明显(请参阅http://git-scm.com/docs/git -rebase#_bugs )。
But there is a simple solution without rebasing:但是有一个简单的解决方案,无需重新定位:
# make sure your working copy is clean, do git stash if needed
git checkout feature1
git reset --soft ff2f539
git commit -m "..."
This will produce one commit including all changes after ff2f539.这将产生一个提交,包括 ff2f539 之后的所有更改。
如果要在 rebase 中包含合并提交,请将--preserve-merges
选项传递给git rebase
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.