Referencing commits
As you continue to make changes and commit them, Git keeps a detailed history of these commits. To see this history, we use the git log command.
Run the git log
command to see the commit history.
Tip: Some Git commands, such as git log
, may put your terminal into pager mode, which is designed for browsing long lists. In this mode, you can scroll through the output using the and arrow keys on your keyboard. To exit pager mode, press q.
You should have seen blocks of something like this:
commit 346ca091076783c70623aba03fb7139d3d27134f
Author: Your Name <you@example.com>
Date: 2024-03-15
Added H1, HTML, and BODY tags to hello.html
Here, 346ca091076783c70623aba03fb7139d3d27134f
is the commit's SHA-1 hash, a unique identifier for that particular commit.
Many Git commands require a commit reference as an argument to pinpoint exactly which version of the code you're interested in. For instance, git diff
, git show
, or git revert
often need to be launched with a commit ID as an argument to function properly.
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~2
, which means the second commit beforeHEAD
, orHEAD^
, which means the commit before the latest).
Hi! I'm Alex, creator of GitByBit.
This page is a part of the interactive course about Git version control.
It's a one-of-a-kind course that is integrated into the VS Code code editor. Learning directly in VS Code lets you operate Git exactly as you would in real life, doing real jobs, writing real code.
In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.