Squash older commits while preserving SHA1s of newer commits

十年热恋 提交于 2019-12-08 05:18:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!