问题
I have a commit history like this:
f85179d ten
7de4071 nine
5c7a482 eight
9585035 seven
b41bffc six
d102f05 five
5a28cb9 four
6fc27c9 three
524b0c7 two
bb7e6ae one
I would like to squash commits "one" to "five" into a single commit such that it looks like this:
f85179d ten
7de4071 nine
5c7a482 eight
9585035 seven
b41bffc six
4tg56y5 Squash five commits into one commit.
Importantly, I want to keep the SHA values the same for the unsquashed commits. That means I cannot just use `git rebase --root -i", because it will change all the hashes.
回答1:
It is not possible to rewrite the history of your git repository and maintain the commit ids of existing commits. A commit id is generated from the content of a given commit (including the contents of the directory tree, the author, committer, date, etc) as well as the id of its parent. This means that if you change any commit in your history, every subsequent commit is going to have a new commit id.
For more details about the format of git repositories, see this doc, or this one.
来源:https://stackoverflow.com/questions/28568068/squash-older-commits-while-preserving-sha1s-of-newer-commits