Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the same git script is producing different hashes?

Tags:

git

hash

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?

like image 697
andref Avatar asked May 28 '13 20:05

andref


2 Answers

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.

like image 54
Fred Foo Avatar answered Sep 30 '22 17:09

Fred Foo


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]>'
like image 35
Abe Voelker Avatar answered Sep 30 '22 19:09

Abe Voelker