我使用这两篇文章的组合来折叠我的Git历史记录:折叠git仓库的历史记录和如何合并Git仓库的前两个提交?
这是结果。
git rebase -i THE_SHA_1_OF_FIRST_COMMIT
# change "pick" into "squash" for all commits except first one
# :wq (if your editor is vi)
git rebase -i THE_SHA_1_OF_FIRST_COMMIT
# change "pick" into "edit"
# :wq (if your editor is vi)
git reset --soft HEAD^
git commit --amend
git rebase --continue
# garbage collect
git reflog expire --expire=1.minute refs/heads/master
git fsck --unreachable
git prune
git gc
这个功能很好,但由于我经常使用它,希望能够在脚本中自动化它。问题是有些命令(如“git rebase -i”)会打开一个文件进行编辑,我必须手动完成(对于“git commit --amend”也是同样的问题)。有没有办法自动化这个过程?我不是要求现成的解决方案,只需要想法。