{"thread":{"id":"18141","subject":"just curious: what influences a commit hash?","startedAt":"2009-03-05T06:36:32Z","lastAt":"2009-03-05T10:38:08Z","messageCount":4,"participants":["stoecher@gmx.at","Matt Enright","Uwe Kleine-König","Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"107019","messageId":"20090305063632.42880@gmx.net","threadId":"18141","inReplyTo":null,"subject":"just curious: what influences a commit hash?","fromName":"","fromEmail":"stoecher@gmx.at","sentAt":"2009-03-05T06:36:32Z","receivedAt":"2009-03-05T06:36:32Z","isPatch":false,"sender":{"key":"stoecher@gmx.at","avatar":null},"body":"Hi,\n\nbeing new to git I did some experiments with commits looking at the hashes. What I observed:\n* 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?\n* 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!?\n\nFrom 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?\n\nthank you,\n\nWolfgang\n\n-- \nComputer Bild Tarifsieger! GMX FreeDSL - Telefonanschluss + DSL\nfür nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a\n"},{"id":"107023","messageId":"1236237939.2421.38.camel@virgil","threadId":"18141","inReplyTo":"20090305063632.42880@gmx.net","subject":"Re: just curious: what influences a commit hash?","fromName":"Matt Enright","fromEmail":"awickedshimmy@gmail.com","sentAt":"2009-03-05T07:25:39Z","receivedAt":"2009-03-05T07:25:39Z","isPatch":false,"sender":{"key":"awickedshimmy@gmail.com","avatar":null},"body":"On Thu, 2009-03-05 at 07:36 +0100, stoecher@gmx.at wrote:\n> Hi,\n> \n> being new to git I did some experiments with commits looking at the hashes. What I observed:\n> * 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?\n> * 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!?\n\nThis should be expected if the initial hashes in the history are\ndifferent. The hash of a commit is based also on the hashes of all\nparent commits - in this way git 'protects' the repository history by\nguaranteeing that if two objects have the same hash, they will come from\nthe same history.\nSo the second issue is a consequence of the first, though I am not\ncertain why the first occurs (if the file contents and size are the\nsame, I would expect the hash for the blob/tree to be the same - maybe\ndue to git's special handling of initial commits?)\n\n> 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?\n> \n> thank you,\n> \n> Wolfgang\n> \n"},{"id":"107033","messageId":"20090305090221.GA28687@pengutronix.de","threadId":"18141","inReplyTo":"1236237939.2421.38.camel@virgil","subject":"Re: just curious: what influences a commit hash?","fromName":"Uwe Kleine-König","fromEmail":"u.kleine-koenig@pengutronix.de","sentAt":"2009-03-05T09:02:21Z","receivedAt":"2009-03-05T09:02:21Z","isPatch":false,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hi,\n\nOn Thu, Mar 05, 2009 at 02:25:39AM -0500, Matt Enright wrote:\n> On Thu, 2009-03-05 at 07:36 +0100, stoecher@gmx.at wrote:\n> > Hi,\n> > \n> > being new to git I did some experiments with commits looking at the hashes. What I observed:\n> > * 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?\nYes, commit time and commit date influence the hash.\n\nBut the hashes for the corresponding trees should be the same.\nCheck the output of git rev-parse $commit^{tree}.\n\nIf you want to reproduce the exact same commit, you need to set\nthe env variables GIT_AUTHOR_DATE and GIT_COMMITTER_DATE.  (Not sure,\nbut GIT_AUTHOR_DATE might be handled by git am.)\n\nBest regards\nUwe\n\n-- \nPengutronix e.K.                              | Uwe Kleine-König            |\nIndustrial Linux Solutions                    | http://www.pengutronix.de/  |\n"},{"id":"107052","messageId":"vpq7i3445m7.fsf@bauges.imag.fr","threadId":"18141","inReplyTo":"20090305063632.42880@gmx.net","subject":"Re: just curious: what influences a commit hash?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2009-03-05T10:38:08Z","receivedAt":"2009-03-05T10:38:08Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"stoecher@gmx.at writes:\n\n> Hi,\n>\n> being new to git I did some experiments with commits looking at the hashes. What I observed:\n> * The same commit (same file, same committer, same message) into\n> different empty repositories (git init) gives different hashes. So I\n> assume that also the time of the commit influences the hash. Is this\n> intended? For what reason?\n\nYou should distinguish \"commit objects\" from \"tree objects\". You can\nsee the \"commit\" object with, for example:\n\n$ git cat-file -p HEAD\ntree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\nauthor Matthieu Moy <Matthieu.Moy@imag.fr> 1236249249 +0100\ncommitter Matthieu Moy <Matthieu.Moy@imag.fr> 1236249249 +0100\n\nfoo\n\nSee: it contains a reference to the tree, possibly references to the\nparents, and a timestamp. So, hashing it takes the timestamp into\naccount. A consequence of this is that you can not change the\ntimestamp for a commit without changing the \"revision identifier\"\n(i.e. the hash of the commit object).\n\nBut the empty tree object is deterministically\n4b825dc642cb6eb9a060e54bf8d69288fbee4904.\n\n-- \nMatthieu\n"}]}