git rebase -i — why is it changing commit hashes?

前端 未结 5 1135
情书的邮戳
情书的邮戳 2021-02-05 17:09

So I\'m more or less familiar with how rebasing works, but up until recently I usually just did a git rebase -i HEAD~20, and modified whatever needed to be modified

5条回答
  •  别跟我提以往
    2021-02-05 18:04

    You may feel that you didn't change some commits, but you actually changed them in several ways:

    • Each commit contains the sha1 of its parents. So, changing the sha1 of a parent modifies the commit, hence its sha1. The hashes are chained, changing anything in the past changes the future. Technically, this is called a Merkle tree. This is an important property of Git, because given a sha1 it guarantees not only the integrity of the current commit but also of the whole history leading to it (assuming you can't find a collision in sha1, which is no longer really the case today, but collisions are still very hard to find).

    • Each commit contains a snapshot of the current state of your project. Hence, even if a commit seems identical because it introduces the same diff, it may not correspond to the same state of the project (to the same tree object).

    • As already noted, commits contain timestamps (one timestamp for the author, one for the commiter, the second one being changed when you rebase).

提交回复
热议问题