我试图合并2个提交为1,所以我遵循“压缩提交与rebase”从git就绪。
我跑
git rebase --interactive HEAD~2
在结果编辑器中,我将pick更改为squash,然后save-quit,但由于出现错误,重基操作失败
没有之前的提交就不能“squash”
现在我的工作树已经达到了这个状态,我很难恢复。
命令git rebase——interactive HEAD~2失败:
交互式改基已经开始
git rebase -continue失败
没有之前的提交就不能“squash”
因为我对几乎所有的东西都使用git,所以对我来说,即使在这里这样做也是很自然的。
假设我签出了branchX,在它的顶端有两个提交,其中我想创建一个合并它们内容的提交,我这样做:
git checkout HEAD^ // Checkout the privious commit
git cherry-pick --no-commit branchX // Cherry pick the content of the second commit
git commit --amend // Create a new commit with their combined content
如果我想更新branchX以及(我认为这是这个方法的缺点),我也必须:
git checkout branchX
git reset --hard <the_new_commit>