我试图合并2个提交为1,所以我遵循“压缩提交与rebase”从git就绪。
我跑
git rebase --interactive HEAD~2
在结果编辑器中,我将pick更改为squash,然后save-quit,但由于出现错误,重基操作失败
没有之前的提交就不能“squash”
现在我的工作树已经达到了这个状态,我很难恢复。
命令git rebase——interactive HEAD~2失败:
交互式改基已经开始
git rebase -continue失败
没有之前的提交就不能“squash”
我经常使用git reset -mixed在你想合并的多次提交之前恢复一个基本版本,然后我做一个新的提交,这样可以让你提交最新的版本,确保你推送到服务器后你的版本是HEAD。
commit ac72a4308ba70cc42aace47509a5e
Author: <me@me.com>
Date: Tue Jun 11 10:23:07 2013 +0500
Added algorithms for Cosine-similarity
commit 77df2a40e53136c7a2d58fd847372
Author: <me@me.com>
Date: Tue Jun 11 13:02:14 2013 -0700
Set stage for similar objects
commit 249cf9392da197573a17c8426c282
Author: Ralph <ralph@me.com>
Date: Thu Jun 13 16:44:12 2013 -0700
Fixed a bug in space world automation
如果我想合并头两个提交为一个,首先我使用:
git reset --mixed 249cf9392da197573a17c8426c282
“249cf9392da197573a17c8426c282”是第三个版本,也是你合并之前的基础版本,在那之后,我做了一个新的提交:
git add .
git commit -m 'some commit message'
希望对每个人来说都是另一种方式。
供参考,从git重置——帮助:
--mixed
Resets the index but not the working tree (i.e., the changed files are
preserved but not marked for commit) and reports what has not been
updated. This is the default action.
假设你在自己的主题分支里。如果你想把最后两个提交合并成一个,看起来像一个英雄,就在你做最后两个提交之前分支提交(使用相对提交名称HEAD~2指定)。
git checkout -b temp_branch HEAD~2
然后在这个新分支中挤压提交另一个分支:
git merge branch_with_two_commits --squash
这将带来改变,但不会导致改变。所以只要承诺就行了。
git commit -m "my message"
现在您可以将这个新的主题分支合并回您的主分支。