为什么只推挤压扁的提交?这听起来很疯狂(和错误)。
但是,为了回答你的问题:
git checkout -b newbranch # checkout new branch
git reset --soft C# move to commit C
git add -u # add all changes to index
git commit -m 'squashed commit'
另一种可能性是使用rebase -i
壁球/修正所有提交到一个单一的一个:
git checkout -b newbranch
git rebase -i C# now, replace every 'pick' with 'fixup'/'squash' except the first one
的利益也就是git merge --squash
:
生成工作树和索引状态,就好像发生了真正的合并(exc ept为合并信息),但不实际提交或移动HEAD,也不记录$ GIT_DIR/MERGE_HEAD以使下一个git commit命令创建合并提交。这允许您在当前分支上创建一个单独的提交,其效果与合并另一个分支相同(或者在章鱼的情况下更多)。
git checkout -b newbranch C# create newbranch at commit C
git merge --squash mybranch
git commit -m 'squashed commit'
这样做了,谢谢! – Phillip