Git development
 help / color / mirror / Atom feed
* just curious: what influences a commit hash?
@ 2009-03-05  6:36 stoecher
  2009-03-05  7:25 ` Matt Enright
  2009-03-05 10:38 ` Matthieu Moy
  0 siblings, 2 replies; 4+ messages in thread
From: stoecher @ 2009-03-05  6:36 UTC (permalink / raw)
  To: git

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?
* Having created two repositories exactly the same way (the history is the same except for the commit times and hashes) I applied the same patch (using git am) and again I got different hashes for these commits. So in some way also the repository/branch influences the hash of a commit!?

From reading the Git user's manual, chapter 10, object storage format, I was not expecting this. Can someone explain or give a link to a more detailed description?

thank you,

Wolfgang

-- 
Computer Bild Tarifsieger! GMX FreeDSL - Telefonanschluss + DSL
für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: just curious: what influences a commit hash?
  2009-03-05  6:36 just curious: what influences a commit hash? stoecher
@ 2009-03-05  7:25 ` Matt Enright
  2009-03-05  9:02   ` Uwe Kleine-König
  2009-03-05 10:38 ` Matthieu Moy
  1 sibling, 1 reply; 4+ messages in thread
From: Matt Enright @ 2009-03-05  7:25 UTC (permalink / raw)
  To: stoecher; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1458 bytes --]

On Thu, 2009-03-05 at 07:36 +0100, stoecher@gmx.at wrote:
> 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?
> * Having created two repositories exactly the same way (the history is the same except for the commit times and hashes) I applied the same patch (using git am) and again I got different hashes for these commits. So in some way also the repository/branch influences the hash of a commit!?

This should be expected if the initial hashes in the history are
different. The hash of a commit is based also on the hashes of all
parent commits - in this way git 'protects' the repository history by
guaranteeing that if two objects have the same hash, they will come from
the same history.
So the second issue is a consequence of the first, though I am not
certain why the first occurs (if the file contents and size are the
same, I would expect the hash for the blob/tree to be the same - maybe
due to git's special handling of initial commits?)

> From reading the Git user's manual, chapter 10, object storage format, I was not expecting this. Can someone explain or give a link to a more detailed description?
> 
> thank you,
> 
> Wolfgang
> 

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: just curious: what influences a commit hash?
  2009-03-05  7:25 ` Matt Enright
@ 2009-03-05  9:02   ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2009-03-05  9:02 UTC (permalink / raw)
  To: Matt Enright; +Cc: stoecher, git

Hi,

On Thu, Mar 05, 2009 at 02:25:39AM -0500, Matt Enright wrote:
> On Thu, 2009-03-05 at 07:36 +0100, stoecher@gmx.at wrote:
> > 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?
Yes, commit time and commit date influence the hash.

But the hashes for the corresponding trees should be the same.
Check the output of git rev-parse $commit^{tree}.

If you want to reproduce the exact same commit, you need to set
the env variables GIT_AUTHOR_DATE and GIT_COMMITTER_DATE.  (Not sure,
but GIT_AUTHOR_DATE might be handled by git am.)

Best regards
Uwe

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: just curious: what influences a commit hash?
  2009-03-05  6:36 just curious: what influences a commit hash? stoecher
  2009-03-05  7:25 ` Matt Enright
@ 2009-03-05 10:38 ` Matthieu Moy
  1 sibling, 0 replies; 4+ messages in thread
From: Matthieu Moy @ 2009-03-05 10:38 UTC (permalink / raw)
  To: stoecher; +Cc: git

stoecher@gmx.at writes:

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-03-05 10:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-05  6:36 just curious: what influences a commit hash? stoecher
2009-03-05  7:25 ` Matt Enright
2009-03-05  9:02   ` Uwe Kleine-König
2009-03-05 10:38 ` Matthieu Moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox