CodeBlanks Logo Icon CodeBlanks

HEAD history

Learn to list all HEAD movements.

HEAD history

HEAD is a special reference that tracks the commit or branch you are currently working on. Every position HEAD moves to is recorded in reflog in chronological order. These records let you inspect which commit you moved from and which commit you moved to.

git reflog

# Inspect a specific movement
git show HEAD@{2}

Reflog entries are ordered from the newest movement to the oldest.

Filter HEAD movements

By default, reflog displays HEAD entries; the --all option helps list reflog entries for all references in the repository. The standard git reflog command is sufficient when you only need HEAD history. You can use the -n option to inspect a specific number of recent entries.

git reflog -n 5

This command lists the five most recent HEAD movements.

Practice Display a limited HEAD history

Write a command that lists only the four latest HEAD movements in the terminal. Then inspect the commit referenced by the latest entry using git show.

Starter code

terminal
# Son dört hareketi göster

# En son commit'i incele

Sample solution

terminal
# Son dört hareketi göster
git reflog -n 4

# En son commit'i incele
git show HEAD@{0}

Expected output

a1b2c3d Son commit

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does HEAD@{2} represent?

  • Two different repositories
  • The position two movements before the latest Correct answer
  • The second branch in the remote repository
  • The file count of the second commit

Explanation: <code>HEAD@{2}</code> refers to the HEAD movement two entries before the newest reflog entry.

2 List the three latest HEAD movements

Question
git reflog -n ____
Answer
git reflog -n 3

Explanation: The <code>-n 3</code> option limits reflog output to the three most recent entries.

3 HEAD history concepts

Term Meaning
HEAD Tracks the current position
HEAD@{0} Newest movement
HEAD@{2} Movement two entries earlier
-n 5 Shows the latest five entries

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow