我找到了解决方案:
rebase --interactive 完成这项工作,如果我在初始提交之前将提交的哈希传递给 squash:
git rebase -i --no-autosquash "<hash of comitt BEFORE FeatureX>"
这将打开一个文本文件,如
pick 07b952c some unrelated committ
pick 6c46e25 FeatureX
pick b4bc625 B
pick f2fab98 C
pick dc6ba8b D
pick 5633408 FixBugInFeatureX
pick 077888f E
pick 0123445 F
# Rebase xxx..yyy onto zzz
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
我现在可以将此文件修改为
pick 07b952c some unrelated committ
pick 6c46e25 FeatureX
squash 5633408 FixBugInFeatureX
pick b4bc625 B
pick f2fab98 C
pick dc6ba8b D
pick 077888f E
pick 0123445 F
并且 git 会将两个提交压缩在一起。之后将显示一个可编辑的文本文件,我可以在其中编辑 6c46e25 的新提交消息,现在还包括 5633408
如果在两个提交之间进行了合并或推送/拉取,这将无法令人满意。这导致至少在我的试验中重复历史。但除此之外,这正是我想要的。没有重复的历史。显然,重点是在第一次提交编辑之前传递提交的哈希值。