Lessons · Git · is it the tree or the history
Wrong files, or wrong history
Two different problems with two different sets of commands. git status answers which one you have, in one line or none.
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
Reaching for reset when a file is wrong throws away more than you meant; reaching for restore when the history is wrong does nothing at all.
How to think about it
If status shows changes, deal with those first -- they are the only thing on this road with no undo. Once it is clean, the problem is in the commits.
Worked example
git status --shortUncommitted work. Nothing about the history is safe to try yet.
git stashNow it is a commit object, and safe.
git status --shortSilence. Whatever is wrong now, it is in the commits.
git log --onelineAnd this is the part to look at.
git stash popThe work comes back when you are ready for it.
Your turn
Put the uncommitted work somewhere safe before touching the history.
git
Try it in a real repository
The trap
Treating a clean status as good news. It is only information: it says the problem is somewhere more expensive.