Git Reflog guide - How to view a full history log of all recent changes to a Git repo

November 14, 2020

If you have ever made some changes in Git, such as merging or deleting some commits and realised you need to go back in time then you need to use the git reflog command to see your recent changes.

git reflog

You will see output such as

92c0d87 (HEAD -> master) HEAD@{0}: commit: feat: add payments
5a33207 (origin/master) HEAD@{1}: commit: fix: css on subscription page
5d9cf54 HEAD@{2}: commit: feat: subscription info page
3b71063 HEAD@{3}: commit: feat: account forgot password
343be53 HEAD@{4}: commit: feat: account auth
f0d1c71 HEAD@{5}: rebase -i (finish): returning to refs/heads/master
f0d1c71 HEAD@{6}: rebase -i (continue): feat: profile page
137bd7e HEAD@{6}: rebase -i (pick): feat: nav with profile
f71093f HEAD@{7}: rebase -i (pick): feat: account
7604823 HEAD@{8}: rebase -i (pick): feat: public site
92c0d87 (HEAD -> a-new-branch, master) HEAD@{9}: checkout: moving from master to a-new-branch

As you can see from the example it will show every single commit, branch change etc.

You can then checkout those commits, by either git checkout 5d9cf54 or git checkout HEAD@{2}.

If you need to reset the current branch to one of those commit then just do git reset 5d9cf54 or git reset HEAD@{2}.

Further reading: https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog