CodeBlanks Logo Icon CodeBlanks

Summary - Reflog

Combine the reflog flow to safely recover.

Safe recovery with reflog

Reflog helps you find previous HEAD positions after accidental resets or branch switches. First identify the correct commit with git reflog, then inspect its contents with git show. Protect the commit by creating a new branch so it does not become difficult to reach again.

git reflog
git show a1b2c3d
git branch recover a1b2c3d

After protecting the commit, you can switch to the recovery branch and continue your work.

Practice Complete the recovery workflow

Use b7c8d9e as the example commit identifier. First point a new branch named safe to the commit, then inspect that branch's contents with git show, and finally switch to the branch. Complete the commands in the specified order.

Starter code

terminal
# Commit'i koru

# Dalın commit'ini incele

# Kurtarma dalına geç

Sample solution

terminal
# Commit'i koru
git branch guvenli b7c8d9e

# Dalın commit'ini incele
git show guvenli

# Kurtarma dalına geç
git switch guvenli

Expected output

Switched to branch 'guvenli'

Questions and answers

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

1 What is the safest first step during recovery?

  • Find the commit in reflog and inspect it Correct answer
  • Run another reset --hard
  • Delete all remote branches
  • Delete the repository's .git directory

Explanation: You should first identify the correct commit in reflog and inspect its contents. This reduces the risk of recovering the wrong commit.

2 Place the commit on a recovery branch

Question
git branch guvenli ____
Answer
git branch guvenli b7c8d9e

Explanation: The commit identifier is passed to the branch creation command to protect the old commit with a branch reference.

3 Safe recovery workflow

Term Meaning
git reflog Find the previous HEAD position
git show Verify the commit contents
git branch Protect the commit
git switch Switch to the recovery branch

All lessons in Intermediate

20 Intermediate final

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