git reflog
git reflog: display reference log, showing updates to the tip of branches and other references.
Git records every move of HEAD and your branches in the reflog, so this command is the fastest way to see where a reference pointed earlier and rescue a commit that no longer belongs to an obvious branch. The log lives only on your machine, which makes it perfect for undoing mistakes in your current clone without affecting collaborators.
Example
git refloga7f3c9b (HEAD -> feature/api-refactor) HEAD@{0}: commit: Add error handling middleware
b12ad6f HEAD@{1}: commit: Refactor API routes and controllers
e93b4c2 HEAD@{2}: rebase -i (finish): returning to refs/heads/feature/api-refactor
e93b4c2 HEAD@{3}: rebase -i (pick): Clean up old utility functions
a57de29 HEAD@{4}: checkout: moving from main to feature/api-refactor
c1a9f3b (tag: v1.4.2, origin/main, main) HEAD@{5}: merge feature/dashboard: Merge made by the 'ort' strategy.
5b8f021 HEAD@{6}: commit: Update CHANGELOG and bump version
0cf2a11 HEAD@{7}: tag: v1.4.2: tagging version 1.4.2 release
fd61b7b HEAD@{8}: commit: Fix dashboard layout issues on Safari
a28c90c HEAD@{9}: checkout: moving from hotfix/security-patch to main
f4e35ad (hotfix/security-patch) HEAD@{10}: commit: Patch XSS vulnerability in comments
9e0cd43 HEAD@{11}: checkout: moving from main to hotfix/security-patch
a28c90c HEAD@{12}: pull origin main: Fast-forward
f01d1a2 HEAD@{13}: commit: Improve documentation for API usage
e712d8e HEAD@{14}: reset: moving to HEAD~1
f8d7a1b HEAD@{15}: commit (amend): Update README.md with new badges
b19d2aa HEAD@{16}: commit: Add README.md
eac51bb (tag: v1.4.1) HEAD@{17}: checkout: moving from feature/login to main
b9d0f4c HEAD@{18}: commit: Fix login redirect loop
fa8c121 HEAD@{19}: checkout: moving from main to feature/login
a28c90c HEAD@{20}: merge origin/main: Fast-forward
The list is ordered in reverse chronological order, with the most recent action at the top. Let's break down the top few entries:
- Commit hash of the commit that HEAD pointed to after this action (
a7f3c9b,b12ad6f, etc.) - Optional ref names of any branches or tags currently pointing to that commit (
feature/api-refactor,main,v1.4.2, etc.) - Reflog reference—the numbered identifier (e.g.
HEAD@0,HEAD@1) you can use to refer back to this exact point inHEADhistory. - Action description—a brief note describing the operation that moved
HEADto this commit (e.g.commit,checkout,merge,rebase (finish), etc.)
Examples
List the recent history of HEAD movements in the repository:
git reflogReset the current branch to the state it was 2 moves ago, using the reflog reference:
git reset --hard HEAD@{2}Reset the current branch to whatever state the branch main was in at a specific time (assuming the reflog contains an entry for that moment, such as yesterday):
git reset --hard main@{yesterday}