Git and GitHubgit 2.54 · GitHub · macOS, Linux or Windows
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
26 small wins to finish your pathNext lesson →

Looking at history with git log

git log is the command that prints the commits of the branch you are on, newest first, with the identifier, author, date and message of each.

Last updated: 12 Oct, 2026 · git 2.54

Committing writes the history. Reading it is how you find out when a value changed, which commit touched a file, and what the person who wrote it was trying to do. One command does all of that, and its flags decide how much of each commit you see.

Reading the history with git log · from the Git and GitHub series · 11:01 to 11:45

Syntax: git log with no arguments prints the whole history of the current branch. Flags cut it down.

bash
git log                 # every commit, newest first
git log --oneline -n 5  # the last five, one line each

The history these examples read

Every block on this page reads the same repository: three commits made on three days. The first two blocks build it, and the ones after them start from the same twelve lines without repeating them.

ExampleThe first commit, printed in full
mkdir ask-docs && cd ask-docs && git init -q -b main
# one fixed date per commit, so every run gives the same hashes
export GIT_AUTHOR_DATE="2026-10-10T09:00:00+00:00" GIT_COMMITTER_DATE="2026-10-10T09:00:00+00:00"
printf 'Support bot\n' > README.md
printf 'You are a support assistant.\n' > prompt.txt
git add . && git commit -q -m "Add the README and the first prompt"
git log
  • commit a290cb35... is the identifier, forty characters computed from the commit's content, its parent and its author. No two commits share one.
  • Author is the name and email from your configuration, copied in at commit time.
  • Date is the moment the commit was made, in your time zone. The commits on this page carry a fixed date and a zero offset because the examples set them.
  • The message is indented under the header. It is the only part a human wrote.

Two more commits follow, each with its own date and its own message.

ExampleThe same history after two more commits
export GIT_AUTHOR_DATE="2026-10-11T11:30:00+00:00" GIT_COMMITTER_DATE="2026-10-11T11:30:00+00:00"
printf 'chunk_size = 500\n' > loader.py
git add . && git commit -q -m "Split documents into 500 character chunks"
export GIT_AUTHOR_DATE="2026-10-12T10:00:00+00:00" GIT_COMMITTER_DATE="2026-10-12T10:00:00+00:00"
printf 'You are a support assistant. Answer only from the documents.\n' > prompt.txt
git commit -q -am "Tell the model to answer only from the documents"
git log
The three commits of the ask-docs repository drawn as a chain. Each commit points back to its parent, so the newest commit, Tell the model to answer only from the documents, points to Split documents into 500 character chunks, which points to the first commit, Add the README and the first prompt. The branch name main points at the newest commit and HEAD points at main. One commit is opened up to show its four parts: the identifier, the author, the date and the message.

The newest commit is at the top. Each commit also records its parent, the commit that came before it, which is how Git knows the order.

Where the author name comes from

Every line of the Author field was read from your global configuration when the commit was made. The examples on this page run with this file in place:

ini
[user]
	name = Reader
	email = reader@example.com

Changing that file changes the author of your next commit. It does not change the ones already made, because the name is stored inside each commit.

One line per commit

--oneline shortens each commit to its short identifier and the first line of its message. This is the form you will use most.

ExampleThe same history, one line per commit
git log --oneline

The short identifier is the first seven characters of the long one, which is enough to name a commit in almost every repository.

ExampleOnly the two most recent commits
git log --oneline -n 2

-n 2 stops after two commits. --oneline is also what makes the first line of a commit message worth writing carefully, which the message page covers.

Which files a commit touched

--stat adds the file names and a count of changed lines under each commit.

ExampleWhat the newest commit touched, by file
git log --stat -n 1
  • prompt.txt | 2 +- says one line went in and one went out of that file.
  • 1 file changed, 1 insertion(+), 1 deletion(-) is the summary across the commit.

-p goes further and prints the changed lines themselves.

ExampleThe newest commit, line by line
git log -p -n 1

The block under -p is the same change written as a patch: the line starting with - was removed and the line starting with + replaced it. The diff page reads that format in full.

Narrowing the history

Three flags answer most questions you bring to a history: the commits that touched one file, the commits whose message mentions a word, and a format of your own.

ExampleOnly the commits that touched prompt.txt
git log --oneline -- prompt.txt

-- prompt.txt keeps only the commits that changed that file. The two dashes separate paths from flags, so Git does not mistake a file name for an option.

ExampleOnly the commits whose message mentions chunk
git log --oneline --grep=chunk

--grep=chunk searches the messages, not the code. -S chunk_size searches the code instead.

ExampleA line built out of placeholders
git log --pretty=format:'%h %ad %an %s' --date=short

--pretty=format: builds a line out of placeholders: %h short identifier, %ad author date, %an author name, %s the subject. --date=short prints the date as a plain day.

The flags worth remembering

FlagWhat it addsReach for it when
--onelineone line per commityou want the shape of the history
-n <k>stops after k commitsonly the recent ones matter
--statfiles and line countsyou ask what a commit touched
-pthe changed linesyou ask exactly what changed
-- <path>only commits touching that pathone file behaves oddly
--grep=<word>only matching messagesyou remember a word from a message
--graph --alla drawing of every branchbranches have split and merged

Where you read the history

  • Before changing a file you did not write. git log -p -- loader.py shows every change that file has had and why.
  • When a setting stops working. Find the commit that changed it, read its message, and you have the reason.
  • Before you write your own message. Reading the last ten lines of --oneline shows the style the project uses.
Watch out. In a terminal, a long git log opens a pager and the terminal seems to stop taking commands. Press q to leave it, the space bar to go down a page. git --no-pager log prints straight out instead. Also, git log shows the history of the branch you are on; the branches page uses --all to see the rest.
Try it yourself
  • Run git log --oneline --stat and compare it with git log --stat.
  • Run git log -S chunk_size, which finds the commits where that text appeared or disappeared in the code.
  • Run git show <short id> with one of the identifiers from your --oneline output. It prints that one commit with its patch.
Previous.gitignore

Little by little, you're building something great.