Git: Roll your own VCS
Early versions of Git (<1.5) were not a complete version control system; instead, they were a series of commands for manipulating the underlying commit graph. The legacy of these beginnings means Git has various ‘plumbing’ commands; commands which manipulate git objects directly.
For example, it’s possible to write anything as a commit object*:
This, obviously, works for files as well:
Using git hash-object
in this way creates a blob which contains the contents
of test.txt
compressed with zlib; this blob is written to disk with a sha1
of the contents as the file name.
Before you can commit this file to the repository, it needs to be added to the index:
A git commit is a pointer to a tree object along with some meta information e.g time and committer details. Obviously, this means a tree object needs to exist before a commit can be made. To create a tree object:
Then to create the commit:
Finally, to point master
to this commit:
Fortunately, all of the above is equivalent to:
* This ultimately means you can use Git for purposes other than version control but that’s another topic entirely.
Summary
Aren’t you glad that modern versions of Git have porcelain commands as well.