同时保留较新提交的SHA1

同时保留较新提交的SHA1

本文介绍了压缩较旧的提交,同时保留较新提交的SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的提交历史记录:

  f85179d 10 
7de4071 9
5c7a482 8
9585035七
b41bffc六
d102f05五
5a28cb9四
6fc27c9三
524b0c7两
bb7e6ae一

我想压扁提交one到five到单个提交中,使其看起来像这样:

  f85179d 10 
7de4071 9
5c7a482 8
9585035 7
b41bffc 6
4tg56y5壁球五个承诺一个承诺。

重要的是,我希望保持SHA值不变以提高未提交的提交。这意味着我不能只使用`git rebase --root -i,因为它会改变所有的哈希值。

是不可能重写你的git仓库的历史维护现有提交的提交id。提交id是从给定提交的内容(包括目录树的内容,作者,提交者,日期等)以及它的父代的id,这意味着如果你改变了历史中的任何提交,每一个后续的提交都会有一个新的提交id。



有关git存储库格式的更多详细信息,请参阅或。

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.

解决方案

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.

这篇关于压缩较旧的提交,同时保留较新提交的SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:27