Re: just curious: what influences a commit hash?
- From
Matthieu Moy <matthieu.moy@imag.fr>
- Date
- Mar 5, 2009, 10:38 UTC
- Message-ID
- <vpq7i3445m7.fsf@bauges.imag.fr>
- In-Reply-To
- <20090305063632.42880@gmx.net>
stoecher@gmx.at writes:
Show 7 quoted lines
> Hi, > > being new to git I did some experiments with commits looking at the hashes. What I observed: > * The same commit (same file, same committer, same message) into > different empty repositories (git init) gives different hashes. So I > assume that also the time of the commit influences the hash. Is this > intended? For what reason?
You should distinguish "commit objects" from "tree objects". You can see the "commit" object with, for example:
$ git cat-file -p HEAD tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 author Matthieu Moy <Matthieu.Moy@imag.fr> 1236249249 +0100 committer Matthieu Moy <Matthieu.Moy@imag.fr> 1236249249 +0100
foo
See: it contains a reference to the tree, possibly references to the parents, and a timestamp. So, hashing it takes the timestamp into account. A consequence of this is that you can not change the timestamp for a commit without changing the "revision identifier" (i.e. the hash of the commit object).
But the empty tree object is deterministically 4b825dc642cb6eb9a060e54bf8d69288fbee4904.
-- Matthieu