Hone

Lessons · Git · unreachable is not deleted

Unreachable is not deleted

A commit nothing points at is still an object in the repository. It stops appearing in ordinary commands and it does not stop existing.

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

It is the reason nearly every 'I lost a commit' ends well. The commit is there; what is missing is a name for it.

How to think about it

Confirm it is still an object, then give it a name. Two commands, and neither of them moves anything you are standing on.

Worked example

git log --oneline --all
Every branch, and the commit is on none of them.
git cat-file -t HEAD@{1}
commit. The object is right there.
git cat-file -p HEAD@{1}
Its author, its tree and its message, unchanged.
git branch found HEAD@{1}
Now something points at it, so it is not going anywhere.
git log --oneline --all
And now it appears, because 'all' means all the branches.

Your turn

Ask git what kind of object that reflog entry is.

git cat-file  HEAD@{1}

The trap

Assuming garbage collection has already run. It leaves unreachable objects alone for weeks, which is why this works so often -- and why it is not a backup.

Practise unreachable is not deleted on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.