合并 git 日志中的旧日志条目

Combine old log entries from git log

我有一个项目,日志如下

commit10
commit09
commit08
commit07
commit06
commit05
...
commit01

我想将提交从 01 到 08 转换为只有一个提交。我想要的结果是

commit10
commit09
commitXX

其中提交消息类似于 'initial commit' 之类的东西。我怎样才能做到这一点?

使用 git rebase 命令,或以交互方式(这很好)如 git rebase -i。特别是,这将是一个 'squash' --- 将一些提交合并到其他提交中。

在这里,执行此操作的最佳方法可能是:git rebase -i HEAD~10 查看最近的 10 次提交。然后,您可以使用交互式提示 select 哪些要 's'quash 哪些要 'p'ick(即保留)。

在你的情况下,这可能看起来像:

p SHA10 commit10
p SHA09 commit09
s SHA08 commit08
s SHA10 commit07
...
s SHA01 commit01

然后它会提示您更改提交消息 - 如果您愿意的话。

如果你想撤销你的rebase,使用git reset --hard ORIG_HEAD --- rebase 将之前的状态保存到ORIG_HEAD