Chapter 8
First aid: when something goes wrong
Updated July 31, 2026
Sooner or later you will delete the wrong commit, roll back the wrong branch, or see a message that makes you want to close the terminal and walk away. Here is the good news: if the work was committed, losing it for good is close to impossible. Git keeps far more than git log shows you. This chapter is about where the emergency exit is.
git reflog: the log of everywhere you have been
git log shows the history of a branch, the chain of commits from the current one back to the first. git reflog shows something else entirely: the history of HEAD itself, a list of every place you have stood.
$ git reflog
024f79c HEAD@{0}: revert: Revert "fixed the typos"
fb4dceb HEAD@{1}: checkout: moving from draft to main
fb4dceb HEAD@{2}:Locked
The rest of this chapter is part of a paid course
You are reading the open part. Buy the course to read the whole chapter.