Lesson 2 · Unit 03
The reflog
Git remembers everywhere HEAD has been
What you practise
- Git records every move of HEAD
- Recover a commit after a bad reset or a deleted branch
- Dangling commits and garbage collection
git stash
Try a question from this lesson
Pick one
git reset --hard HEAD~1 moved main back one commit. Where is the commit that main used to point at?
Correct answer
Still in the object store, with no branch pointing at it
Why
Reset moves a pointer; it deletes no objects. The old commit, its tree and its blobs are all still in .git/objects. The only problem is finding its hash again.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The reflog
Git keeps a private diary of every position HEAD has had: the reflog. Each commit, switch, reset, merge and rebase adds a line.
HEAD@{0} is where HEAD is now, HEAD@{1} is where it was one move ago, and so on. You can use these names anywhere a commit is expected.
$ git reflog
77a052f HEAD@{0}: reset: moving to HEAD~1
c39bd1a HEAD@{1}: commit: two
77a052f HEAD@{2}: commit (initial): one11 more exercises in the app
- 3× multiple choice
- 2× fill the blanks
- 3× type the answer
- 1× true or false
- 1× order the lines
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.