Re:How to publish Git repos that cannot be republished to Gi...
by bathtub365 on Monday November 02, 2020 @07:26PM
(#24975042)
What are the random numbers? Commit hashes are deterministic and based on the commit contents
[ Parent
| on HN ]
Re:How to publish Git repos that cannot be republished to Gi...
by __david__ on Monday November 02, 2020 @08:17PM
(#24975358)
I believe they were using "random" to mean "assorted" (which is perfectly cromulent).
Re:How to publish Git repos that cannot be republished to Gi...
by jaytaylor on Monday November 02, 2020 @08:29PM
(#24975430)
edit- thanks commenters for the correction!
Git commit hashes are indeed deterministic, though it depends on the inputs.
From StackOverflow [0]:
Git uses the following information to generate the sha-1:
* The source tree of the commit (which unravels to all the subtrees and blobs)
* The parent commit sha1
* The author info (with timestamp)
* The committer info (right, those are different!, also with timestamp)
* The commit message
Re:How to publish Git repos that cannot be republished to Gi...
by klodolph on Monday November 02, 2020 @08:46PM
(#24975531)
It's deterministic, you've just changed the inputs. The "committer date" is usually excluded from logs so you don't see it, but it's the only missing input. Here is a demo:
$ git rev-parse HEAD
78d66a4f169fec9cb9b3252f7a22bb020e967cd2
$ git log HEAD
commit 78d66a4f169fec9cb9b3252f7a22bb020e967cd2 (HEAD -> master)
Author: XXXX
Date: Mon Nov 2 20:44:04 2020 -0500
temp2
$ git reset --soft HEAD\^
$ GIT_COMMITTER_DATE='Mon Nov 2 20:44:04 2020 -0500' GIT_AUTHOR_DATE='Mon Nov 2 20:44:04 2020 -0500' git commit -m temp2
[master 78d66a4] temp2
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b
$ git rev-parse HEAD
78d66a4f169fec9cb9b3252f7a22bb020e967cd2
Re:How to publish Git repos that cannot be republished to Gi...
by wldlyinaccurate on Monday November 02, 2020 @08:45PM
(#24975529)
Git commit hashes _are_ deterministic. Run `git cat-file -p <hash>` on your two hashes. The timestamp in the committer field will be different. That is why the hash changed.