Lessons · Git · the short list git cannot get back
The short list git cannot get back
Everything git protects is something it was given. An untracked file removed by clean, and an uncommitted edit overwritten by restore or a hard reset, were never objects and have no copies.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Knowing the list is short is what makes the rest of this road relaxing. Almost nothing is final; these few things are.
How to think about it
Commit or stash before anything that moves history. From that point on, every mistake left is one this road can undo.
Worked example
git status --shortOne tracked file edited, one untracked file beside it.
git stashThe edit becomes an object. That one is now safe.
git clean -fAnd the untracked file is gone, with nothing keeping a copy.
git fsck --unreachableObjects nothing points at -- the stash is in here; scratch.txt never was.
git stash popThe edit comes back.
cat f.txtBoth lines. Stashing was the difference.
Your turn
Turn the uncommitted edit into an object before doing anything else.
git
Try it in a real repository
The trap
Believing the reflog covers everything. It records where HEAD has been, not what your editor had open.