Git is my personal favorite application of a directed acyclic graph. Git, while incredibly powerful, can be confusing because it is abstract. You do need, to a certain extent, understand its internals.
Objects are the unit of storage in Git. They are uniquely identified by the SHA-1 of its contents. They are immutable (i.e. they cannot be changed) .
Commit objects contain information about a revision, pointers to its parents, and additional metadata .
Things to notice about the above example:
- We have 2 branches,
- There are 6 commits.
- Notice how a commit points at its parent. The initial commit, A, has no parent.
HEAD are examples of refs. A ref is a pointer to a commit (or to another ref).
HEAD is a special ref, we’ll come back to this.
Note that when you are “checked out on branch add-feature”, what we really mean is “
HEAD is pointing to the ref add-feature”.
Creating a Branch
git checkout -b add-feature
This does the following: 1. Create a new ref, add-feature, pointing to the same commit that the currently checked out branch was pointing at. 2. Check out your new branch (point HEAD at the newly created ref).
git rebase master
The Rev List
git rev-list HEAD
Print the ancestry graph from the stated location (in reverse chronological order).
I think I’ll leave it at that for now, I’m sure there will be more deep dives into Git in the future.◾
- Git Glossary