Introduction

What is Git reflog

The Git reflog is a reference log file that stores a chronological list of all changes made to the HEAD pointer in your Git repository. HEAD always points to the most recent commit, and the reflog essentially tracks every previous commit ever made in the repo.

Think of the reflog as a logbook for your Git branches and other references. It records every change made to these references, enabling you to rewind time and undo any potentially unwanted actions. This can be incredibly helpful when you:

  • Accidentally commit something you shouldn’t have.
  • Delete a commit or branch by mistake.
  • Need to recall what happened to a specific reference at a particular point in time.

This list is, of course, not exhaustive - I’m sure there are thousands of other mistakes you could possibly fix using reflog.

– Graphite - Every engineer should understand git reflog

(*Please note that it only lives on your local, and does not get pushed to the remove repository: when cloning a brand new repo to you local you get nothing but the clone log in git reflog2026-01-15T153609

Basic Usage

The basic usage to show all reflog entries of “HEAD” pointer, branch, or even stash:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
>   git reflog show HEAD  
    eff544f HEAD@{0}: commit: migrate existing content
    bf871fd HEAD@{1}: commit: Add Git Reflog outline
    9a4491f HEAD@{2}: checkout: moving from main to git_reflog
    9a4491f HEAD@{3}: checkout: moving from Git_Config to main
    39b159a HEAD@{4}: commit: expand on git context 
    9b3aa71 HEAD@{5}: commit: more color clarification
    f34388b HEAD@{6}: commit: expand on color support 
    9962aed HEAD@{7}: commit: a git editor -> the Git editor
    
>   git reflog show otherbranch
    9a4491f otherbranch@{0}: commit: seperate articles into branch PRs
	35aee4a otherbranch{1}: commit (initial): initial commit add git-init and setting-up-a-repo docs

>   git reflog show stash
	0d44de3 stash@{0}: WIP on git_reflog: c492574 flesh out intro

Timed reflags allow you to show reflog entries based on certain time constraint, based on the timestamps attached to the reflog entries:

1
2
3
4
5
6
>   git diff main@{0} main@{1.day.ago} 
    9a4491f HEAD@{3}: checkout: moving from Git_Config to main
    39b159a HEAD@{4}: commit: expand on git context 
    9b3aa71 HEAD@{5}: commit: more color clarification
    f34388b HEAD@{6}: commit: expand on color support 
    9962aed HEAD@{7}: commit: a git editor -> the Git editor

Once you have found the certain reflog entries you want to jump back to, you can revert back to it using the git reset --hard #HASH command. For instance consider you have encountered an issue that break your code base during a rebase (commit 52896f49), and you want to revert to the state before the rebase (commit 7896dbe):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
>   git rebase .... 
    ...............
    ...............
  
>   git reflog show feature
    52896f49 (HEAD -> feature) feature@{0}: rebase: Added new feature post-rebase
    7896dbe feature@{1}: commit: Pre-rebase commit
    43672ac feature@{2}: commit: Another feature update
    987fd12 feature@{3}: commit: Initial feature work
    
>  git reset --hard 7896dbe

(Exampled from the same Graphite blog post: link)

Using Reflog in Lazygit

In lazygit there’s a “commit-reflog” panel, where you can traverse all the reflog entries, using it you can quickly jump/checkout to certain reflog entry using the g key and choose “hard reset” option:

2026-01-15T155047

Moreover, you can also use the z key to undo and Z key to redo the last action, lazygit will utilise the reflog to determine what to do (what’s shown in the below example: fixup all commit into “Initial Commit” and undo that):

2026-01-15T155522

Reference