Commit reference
A commit reference is a way to refer to specific commits when running Git commands. It can be a commit hash, a branch name, a tag, or a special reference 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:
-
Commit hashes: You can use the full 40-character SHA-1 hash (e.g.,
346ca091076783c70623aba03fb7139d3d27134f) or a shortened version (typically the first 7 characters, such as346ca09), as long as it stays unique within the repository. -
Tags: These are human-readable names (e.g.,
v1.0) that can be assigned by you to specific commits. -
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. -
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).
- Reflog references (e.g.,
HEAD@{2}ormain@{yesterday}) let you point to commits as they appear in thegit reflog, which is especially useful when you need to recover a commit that was orphaned or hard to find in the normal history.