Commit reference
A commit reference is a way to refer to specific commits when running Git commands. It can be commit hashes, branch names, tags, or special references such as HEAD~2
. Commit references allow you to navigate through the commit history and perform operations on specific commits.
There are multiple ways to refer to commits. Here are the most common ones:
-
The full SHA-1 hash (e.g.,
346ca091076783c70623aba03fb7139d3d27134f
). -
A shortened SHA-1 hash (the first few characters, usually the first 7, for example,
346ca09
). -
Tags: These are human-readable names (e.g.,
v1.0
) that can be assigned by you to specific commits. We'll cover tags in just a bit. -
Branch names: These are pointers to the latest commit in a branch. Branches (e.g.,
main
,new-dashboard-feature
) are the parallel lines of development in Git. We'll cover branches later as well. -
HEAD
: This is a special reference that points to the latest commit in the current branch. -
Relative references (e.g.,
HEAD~5
, which means the fifth commit beforeHEAD
, orHEAD^
, which means the commit before the latest).