I'm writing a script to serve as an example of Git usage. However, every time I run it, a different set of hashes are produced, even if the commit message, author, date, parent and contents are the same:
rm -rf /tmp/git-teste
git init /tmp/git-teste
cd /tmp/git-teste
echo 'zero' > master.txt
git add .
git commit -am zero --date '2013-05-28 16:40:00' --author 'andre <[email protected]>'
Shouldn't the hash has been always the same? What should I change to assure this happen?
A Git commit has two dates: an author date, which you set with commit --date
, and a commit date. Both are used to compute the SHA1. The commit date can be set using the GIT_COMMITTER_DATE
environment variable, see git help commit-tree
.
larsmans is correct about the commit date being different. Try this for your last line:
GIT_AUTHOR_DATE='2013-05-28 16:40:00' GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE git commit -am zero --author 'andre <[email protected]>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With