gitpractice.dev

brewly — Ch.4 · Get lost commits back

Exercise 6 of 9

Before you start

The reflog remembers

Git keeps a private diary of every place HEAD has been: the reflog. Commits that no branch points to are still there for weeks.

Each line has a name such as HEAD@{1}, meaning "where HEAD was one move ago". You can use it like any commit.

There is no Undo button in this exercise. Real life has none either; the reflog is the way back.

git reflog
list where HEAD has been, newest first
git reset --hard <commit>
move the branch back to a commit
git log --oneline
check what is back
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path