Hone

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 --short
One tracked file edited, one untracked file beside it.
git stash
The edit becomes an object. That one is now safe.
git clean -f
And the untracked file is gone, with nothing keeping a copy.
git fsck --unreachable
Objects nothing points at -- the stash is in here; scratch.txt never was.
git stash pop
The edit comes back.
cat f.txt
Both lines. Stashing was the difference.

Your turn

Turn the uncommitted edit into an object before doing anything else.

git 

The trap

Believing the reflog covers everything. It records where HEAD has been, not what your editor had open.

Practise the short list git cannot get back on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.