Files
DIY_GIT_in_Python/how_to/Change_16.md

923 B
Raw Blame History

  • commit: set parent to HEAD

When creating a new commit, we will use the HEAD to link the new commit to the previous commit. Well call the previous commit the “parent commit” and we will save its OID in the “parent” key on the commit object.

For example, HEAD is currently bd0de093f1a0f90f54913d694a11cccf450bd990 and we create a new commit, the new commit will look like this in the object store:

tree 50bed982245cd21e2798f179e0b032904398485b
parent bd0de093f1a0f90f54913d694a11cccf450bd990

This is the commit message!

The first commit in the repository will obviously have no parent.

Now we can retrieve the entire list of commits just by referencing the last commit! We can start from the HEAD, read the “parent” key on the HEAD commit and discover the commit before HEAD. Then read the parent of that commit, and go back on and on… This is basically a linked list implemented over the object database.