Viewing Commit History
Asha's recipe box now has a dozen commits. She wants to know when the chai recipe got more ginger, and who changed the bread oven temperature. That is exactly what the history is for, and git log is the way in.
The rule
git logreads history newest first; add flags to narrow or reshape it.
The plain command lists each commit with its hash, author, date and message, starting with the latest:
git log
# commit 9b2d7e4a... (HEAD -> main)
# Author: Asha Rao <asha@example.com>
# Date: Tue Mar 3 18:12:40 2026 +0530
#
# Add more ginger to chaiPress q to leave the pager, and the arrow keys or space to scroll.
The flags you will use most:
git log --oneline # one short line per commit
git log -3 # only the last three commits
git log -- chai.md # only commits that changed chai.md
git log -p -- chai.md # the same, with each commit's line changes
git log --author="Asha" # commits by a matching author
git log --grep="ginger" # commits whose message mentions ginger
git log --oneline --graph --all # a picture of every branch--oneline output looks like this:
9b2d7e4 (HEAD -> main) Add more ginger to chai
51c0a88 Fix oven temperature in bread
e3f1b07 Add bread recipe
a17c4d2 Add chai and pancake recipesHEAD -> main marks where you are: HEAD is Git's name for the commit you currently have checked out, here the tip of main.
To look inside a single commit, pass its short hash to git show:
git show 51c0a88It prints the commit's details followed by exactly the lines it added and removed.
You do not always need a hash. Git understands a few relative names: HEAD is the current commit, HEAD~1 is its parent, and HEAD~2 is the one before that. So git show HEAD~1 means "show me the commit before this one", which is handy when you only want to check what you did a moment ago.
Filters can also be combined. git log --oneline --author="Asha" -- chai.md lists only Asha's commits that touched the chai recipe, and --since="2 weeks ago" limits any of these to recent work. Each extra filter narrows the list further, so a question like "what did Asha change in the chai recipe this month?" becomes a single command instead of a long read.