git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: Uwe Kleine-König
Message 4 of 4 in “just curious: what influences a commit hash?”
  1. stoecher@gmx.atMar 5, 2009
  2. Matt EnrightMar 5, 2009
  3. Uwe Kleine-KönigMar 5, 2009
  4. Matthieu MoyMar 5, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.