I performed the first commit and to see what the hash of the tree was I ran the command git cat-file -P HEAD which gave me the following output;
tree ac9b570150cca9243e1546f6c1b393f851dd7559
author pm 1358978176 +1300
committer pm 1358978176 +1300
I then proceed to add a new directory followed by a commit. I then ran the command git cat-file -p HEAD which have me the following output;
tree 297f145b042bf11f16ac39fa109df151a8d56ae3
parent dc2683fdf1bf9d5db5f1dc6fbb62576d10d57ae7
author pm 1358985313 +1300
committer pm 1358985313 +1300
I would thought that the parent hash was that of the preceding commit i.e. ac9b570150cca9243e1546f6c1b393f851dd7559. Have I not understood the use of parent hashes correctly?
ac9b570150cca9243e1546f6c1b393f851dd7559is, according to your information, the hash of the previous tree, not the previous commit. You don’t show the initial commit id here, butgit logwill show it to you.For example, given:
We can run
git cat-file -p HEAD:In this output,
treeis the hash of the current tree, andparentmatches the id of the previous commit.