【发布时间】:2010-10-10 13:33:55
【问题描述】:
使用git rebase --interactive <commit>,您可以将任意数量的提交压缩成一个。
这一切都很好,除非您想将提交压缩到初始提交中。这似乎是不可能的。
有什么方法可以实现吗?
中度相关:
在一个相关问题中,我设法提出了一种不同的方法来解决第一次提交的压缩需求,也就是说,使其成为第二次提交。
如果您有兴趣:git: how to insert a commit as the first, shifting all the others?
【问题讨论】:
-
单行:
git squash 2,别名为squash = !"f() { NL=$1; GIT_EDITOR=\"sed -i '2,$NL s/pick/squash/;/# This is the 2nd commit message:/,$ {d}'\"; git rebase -i HEAD~$NL; }; f"。见stackoverflow.com/a/28789349/670229。 -
'squash' 脚本:两次提交后,该脚本创建的 HEAD~2 不存在,因此在这一特定情况下它不会运行。
标签: git rebase git-rebase squash