Master: git log
In this video we'll learn some of the additional options for
However, more importantly we'll learn to visualize the Git repository.
Often, Git repositories are drawn as a graph, or more simply a tree.
Using a tree analogy can make it easier to describe Git.
So let's use the
--graph option to have
git log draw our commit history.
We see now each commit is represented by an asterisk. All of our commits stack up to form straight line.
We can think of this as the tree's truck or base.
Our Git repository will have a little more shape in Part 3.
For now, let's add the
--decorate option so we can discuss more Git terminology.
We now see our most recent commit is decorated with HEAD.
I skipped over HEAD when discussing
git reset in Part 1. So let's revisit it now.
Technically HEAD is a pointer to the tip of your current branch.
For now, to put it more simply, it's a reference to the most recent commit.
We can use HEAD to relatively reference other commits.
I'll demonstrate relative references with some text comments.
So, our first commit is HEAD.
We can reference the commit before HEAD with HEAD~1 or HEAD^.
We can reference two commits before HEAD with HEAD~2 or HEAD^^.
We can reference three commits before HEAD with HEAD~3 or HEAD^^^.
We can also use the tilde and caret operator with commit SHAs.
So, the same tree can be represented with the following references.
The most recent commit can be HEAD or SHA.
The second most recent commit can be referenced as SHA, SHA~1, or SHA^.
We used this last syntax when we were mastering
git reset to reference the commit before the one we wanted to reset.
Finally, to reference the oldest commit, we can use SHA, SHA^, SHA~2.
While you're welcome to use either syntax, I prefer the tilde to be more more readable and less to type when referencing older commits.
Don't worry if this feels like a lot right now. These relative references and tree analogies are not limited to
git log. We'll use them again with other Git commands.