When a commit occurs, Git records a snapshot of the {{c1::index}} and places that snapshot in the object store. There is a one-to-one correspondence between a commit and a set of changes. A {{c1::commit}} is the only method of introducing changes to a Git repository. How you decide when to commit is up to you and your preferences or development style. Git is well-suited to frequent commits.
Absolute Commit Names
The most rigorous name for a commit is the hash ID which is an absolute name that can only refer to one commit, since it is a globally unique ID.
refs and symrefs
A {{c2::ref}} is a {{c1::SHA1}} hash ID that refers to an object within the Git object store. A {{c2::ref}} may refer to any Git object, but it is usually a {{c1::commit}}. A symbolic reference, or {{c2::symref}}, is just a {{c1::ref}} but it indirectly points to a Git object.
Git maintains several special symrefs automatically. {{c1::HEAD}} is a {{c2::symref}} that always refers to the most recent commit on the current branch. HEAD updates automatically to refer to the latest commit when you change branches. {{c1::ORIG_HEAD}} is the previous version of HEAD recorded after certain operations like merge and reset. FETCH_HEAD is a shorthand for the head of the last branch fetched and is valid only immediately after a fetch operation. {{c1::MERGE_HEAD}} is the tip of the other branch being merged when a merge is in progress. All these special symrefs can be used anywhere a commit can be used.
Relative Commit Names
All commits except for the root commit derive from one or more parent commits. Given a commit with three parents, the three parent commits are C^1, C^2, and C^3. C~1, C~2, and C~3 refer to the first parent, the first grandparent, and the first great-grandparent commits.
Viewing Old Commits
The primary command to show the history of commits is git log.
Commit Graphs
In CS, a {{c1::graph}} is a collection of nodes and a set of edges between the nodes. There are several types of graphs with different properties. Git makes use of a special graph called a {{c1::directed acyclic graph}} to implement the history of commits. There are two important properties of a DAG. First, the edges within the graph are all directed from one node to another. Second, starting at any node, there is no path along the directed edges that leads back to the starting node. Git implements the history of commits as a DAG. In the commit graph, each node is a commit, and all edges are directed from descendent nodes to parent nodes.
The thing to understand is that normal commits have exactly one parent, that there is usually only one commit with zero parents, and that merge commits have more than one parent. A commit with more than one child is where the history diverged into two branches.
Using git bisect
git bisect can be used to isolate and determine that commit that introduced a problem systematically.
Using git blame
git blame tells you who last modified each line of a file and which commit introduced the change.
Using Pickaxe
The -S option to git log searches through the history of a file's diffs for the given string (git log -Sstring). The -S option is called pickaxe.
Article notes
Where does Git place a snapshot of the index when a commit occurs?
The object store
What is the only method of introducing changes to a Git repo?
A commit
What operation causes Git to record a snapshot of the index and place that snapshot in the object store as a tree?
A commit
What is the only means to introduce changes into a Git repository?
A commit
What is the most rigorous name for a Git commit?
The SHA1/hash ID
What term refers to an SHA1 hash ID that refers to an object within the Git object store?
A ref
What type of ref is a name that indirectly points to a Git object?
A symref
What are refs that indirectly point to Git objects (rather than directly) and include HEAD, ORIG_HEAD, etc.?
Symrefs
HEAD, ORIG_HEAD, FETCH_HEAD, are examples of these types of refs that indirectly points to Git objects, usually commits?
symrefs (symbolic references)
What is the special Git symref that updates automatically to refer to the latest commit when you change branches?
HEAD
What is the special symref maintained by Git automatically that refers to the latest commit on the current branch?
HEAD
If a Git commit has three parents, how can the three parent commits be referred to as (relative commit names)?
C^1, C^2, C^3
How can the parent, grandparent, and great-grandparent commits of a git commit be referred to as (relative commit names)?
C~1, C~2, C~3
In Computer Science, what is a collection of nodes and a set of edges between the nodes?
A graph
What is the special type of graph that is used by Git, where all edges are directed, and no path along the directed edges leads back to the starting node?
A directed acyclic graph (DAG)
What is the type of graph that Git uses to implement the history of commits?
A directed acyclic graph
What are the two important properties of a directed acyclic graph noted in the Version Control with Git book?
All edges are directed and there is no path along the directed edges that lead back to the starting node
What is the git command that can be used to systematically isolate and determine a commit that introduced a problem using a clever divide and conquer algorithm?
git bisect
[...] is the tip of the other branch being merged when a merge is in progress.
MERGE_HEAD is the tip of the other branch being merged when a merge is in progress.
A [...] may refer to any Git object, but it is usually a [...].
A ref may refer to any Git object, but it is usually a commit.
In CS, a [...] is a collection of nodes and a set of edges between the nodes.
In CS, a graph is a collection of nodes and a set of edges between the nodes.
[...] is the previous version of HEAD recorded after certain operations like merge and reset.
ORIG_HEAD is the previous version of HEAD recorded after certain operations like merge and reset.
A symbolic reference, or [...], is just a [...] but it indirectly points to a Git object.
A symbolic reference, or symref, is just a ref but it indirectly points to a Git object.
A [...] is the only method of introducing changes to a Git repository.
A commit is the only method of introducing changes to a Git repository.
[...] is a [...] that always refers to the most recent commit on the current branch.
HEAD is a symref that always refers to the most recent commit on the current branch.
When a commit occurs, Git records a snapshot of the [...] and places that snapshot in the object store.
When a commit occurs, Git records a snapshot of the index and places that snapshot in the object store.
A [...] is a [...] hash ID that refers to an object within the Git object store.
A ref is a SHA1 hash ID that refers to an object within the Git object store.
Git makes use of a special graph called a [...] to implement the history of commits.
Git makes use of a special graph called a directed acyclic graph to implement the history of commits.