CodeBlanks Logo Icon CodeBlanks

git reflog

Learn to view HEAD movements with git reflog.

What is git reflog?

git reflog displays a record of HEAD movements in the local repository. New entries are added when operations such as committing, switching branches, resetting, and checking out change the position of HEAD. Reflog can help you find commits that are no longer visible in the normal commit history.

git reflog

# Example output:
a1b2c3d HEAD@{0}: commit: New feature
e4f5g6h HEAD@{1}: checkout: moving from main to feature

Reflog is stored only in the local repository and is not automatically pushed to a remote repository.

Reading reflog entries

Each reflog entry contains a reference, a commit identifier, and a description of the operation. HEAD@{0} represents the latest movement, while HEAD@{1} represents the movement before it. This notation can be used to access a previous position.

git reflog

git show HEAD@{1}

Reflog entries are local and have a limited lifetime, so you should not delay recovery after finding an important commit.

Practice Inspect reflog history

Write a shell command that runs git reflog to display the reflog output. Then add git show HEAD@{1} to display the previous HEAD position.

Starter code

terminal
# HEAD hareketlerini listele

# Önceki HEAD konumunu göster

Sample solution

terminal
# HEAD hareketlerini listele
git reflog

# Önceki HEAD konumunu göster
git show HEAD@{1}

Expected output

a1b2c3d Yeni özellik

Questions and answers

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

1 What information does reflog display?

  • All users in the remote repository
  • The current sizes of files
  • Git configuration settings
  • The local movement history of HEAD Correct answer

Explanation: <code>git reflog</code> lists the positions HEAD moved to in the local repository and the reasons for those movements.

2 Show the previous HEAD position

Question
git show ____
Answer
git show HEAD@{1}

Explanation: <code>HEAD@{1}</code> identifies the commit from the previous reflog movement of HEAD.

3 Reflog terminology

Term Meaning
git reflog Lists HEAD movements
HEAD@{0} Latest HEAD position
HEAD@{1} Previous HEAD position
Yerel kayıt History stored in the repository

All lessons in Intermediate

20 Intermediate final

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