Hone

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-good
A name that will not move.
git reset --hard HEAD~1
Now do something drastic.
git log --oneline
One commit. The branch has moved back.
git rev-parse known-good
The tag has not.
git log --oneline --all
And the commit is still listed, because something points at it.
git reset --hard known-good
Back, without touching the reflog at all.
git tag -d known-good
And the scaffolding comes down.

Your turn

Give this commit a permanent name before doing something risky.

git  known-good

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.