Lessons · Git · what to do before you touch anything
Look before you touch
Three read-only commands answer where you are, what the history looks like, and what is uncommitted. None of them changes anything, so none of them can make it worse.
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
Almost every story that ends with lost work has a command near the start that was typed before anybody knew what state the repository was in.
How to think about it
status, log, branch. Then decide. The temptation is to reach for reset or a fresh clone, and both destroy the evidence you have not read yet.
Worked example
git status --shortOne modified file, unstaged. So there IS uncommitted work here.
git log --onelineOne commit. If you were expecting two, that is the thing to explain.
git branch --show-currentmain. An empty answer here would mean a detached HEAD.
git reflogWhere HEAD has been, newest first -- and the commit that is missing from the log is in it.
Your turn
Show every position HEAD has been in.
git
Try it in a real repository
The trap
Re-cloning. It gets you what the server has, and everything unpushed -- your commits, your stash, your reflog -- is not on the server.