Lessons · Git · marking the known-good point
Marking the known-good point
A tag is a permanent name for a commit. A branch follows you forwards as you commit; a tag stays where it was put.
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
Before anything you are unsure of, a tag turns 'recoverable through the reflog' into 'still right there in git log --all'.
How to think about it
Tag the last state you know was good, do the risky thing, and delete the tag when you no longer want the name.
Worked example
git tag known-goodA name that will not move.
git reset --hard HEAD~1Now do something drastic.
git log --onelineOne commit. The branch has moved back.
git rev-parse known-goodThe tag has not.
git log --oneline --allAnd the commit is still listed, because something points at it.
git reset --hard known-goodBack, without touching the reflog at all.
git tag -d known-goodAnd the scaffolding comes down.
Your turn
Give this commit a permanent name before doing something risky.
git known-good
Try it in a real repository
The trap
Using a branch instead and then committing onto it. A branch moves with you, which is exactly what you did not want here.
Practise marking the known-good point on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.