5

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?

2
  • 1
    Are you deleting /tmp/git-teste first? Commented May 28, 2013 at 20:35
  • 3
    --date overrides the author date. You have a different committer date at every commit. Commented May 28, 2013 at 20:47

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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]>' 

Comments

2

It looks like even if you set author there is a committer field set automatically.

Note that you can find out the difference by looking at the object tree by hand, looking up a different object, and using git cat-file -p A1234 where A1234 is the first 5 characters of the hash (or however many to guarantee uniqueness)

For instance I found the following:

tree 552ae24725bacabda77c585b56b260ccac74c003 author andre <[email protected]> 1369784400 -0700 committer Username <[email protected]> 1369773739 -0700 zero 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.