3 ms·
What are the random numbers? Commit hashes are deterministic and based on the commit contents
by bathtub365 6y ago
What are the random numbers? Commit hashes are deterministic and based on the commit contents
- __david__ 6y agoI believe they were using "random" to mean "assorted" (which is perfectly cromulent).
- jaytaylor 6y agoedit- 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 [0] https://stackoverflow.com/a/34764586/293064 https://stackoverflow.com/a/34764586/293064
- wldlyinaccurate 6y agoGit 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.
- klodolph 6y agoIt'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