[英]Is it possible to rebase and edit a git commit without using interactive rebase?
[英]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.