为什么只推送压扁的提交?这听起来很疯狂(而且是错误的).
但要回答你的问题:
git checkout -b newbranch # checkout new branch
git reset --soft C # move to commit C
git commit -m 'squashed commit'
Run Code Online (Sandbox Code Playgroud)
另一种可能性是用于将rebase -i所有提交压缩/修复为单个提交:
git checkout -b newbranch
git rebase -i C # now, replace every 'pick' with 'fixup'/'squash' except the first one
Run Code Online (Sandbox Code Playgroud)
同样感兴趣的是git merge --squash:
生成工作树和索引状态,好像发生了真正的合并(合并信息除外),但实际上没有提交或移动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'
Run Code Online (Sandbox Code Playgroud)