0
0
Gitdevops~5 mins

Recovering lost commits with reflog in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is git reflog used for?

git reflog shows a log of all recent changes to the HEAD, including commits, resets, and checkouts. It helps find lost commits.

Click to reveal answer
beginner
How can you recover a lost commit using git reflog?

Find the commit hash in git reflog, then use git checkout <commit-hash> or git reset --hard <commit-hash> to restore it.

Click to reveal answer
intermediate
What does the command git reset --hard <commit-hash> do?

It moves the current branch to the specified commit and resets the working directory and staging area to match that commit, discarding changes.

Click to reveal answer
beginner
Why might commits become 'lost' in Git?

Commits can become lost after actions like git reset, git rebase, or branch deletion, but they still exist in reflog for a time.

Click to reveal answer
intermediate
How long does Git keep reflog entries by default?

By default, reflog entries are kept for 90 days before they expire and are removed.

Click to reveal answer
What command lists recent HEAD changes including lost commits?
Agit reflog
Bgit log
Cgit status
Dgit branch
Which command restores your branch to a lost commit found in reflog?
Agit clone &lt;repo&gt;
Bgit push origin main
Cgit merge &lt;commit-hash&gt;
Dgit checkout &lt;commit-hash&gt;
What does git reset --hard <commit-hash> do?
ACreates a new commit
BMoves branch and resets files to that commit
CDeletes the commit permanently
DShows commit details
Why might a commit be missing from git log but visible in git reflog?
ABecause the commit is tagged
BBecause the commit was pushed
CBecause the branch was reset or changed
DBecause the commit is merged
How long does Git keep reflog entries by default?
A90 days
B7 days
CForever
D30 days
Explain how to find and recover a lost commit using git reflog.
Think about how reflog tracks HEAD movements and how to move back to a commit.
You got /3 concepts.
    Describe why commits might become lost and how reflog helps in recovery.
    Consider what happens to commits after branch changes and how reflog records history.
    You got /4 concepts.