World map

 

BM: Baca dalam Bahasa Melayu

World 11: Rescue Center

I deleted a branch

You will learn: how to bring back a branch you deleted by mistake.

The problem

git branch -D about prints: Deleted branch about, was, and a short hash. Terminal output: $ git branch -D about Deleted branch about (was 140649c).

You cleaned up branches with -D. Then you remember: about was never merged! Is your work gone? Breathe. This happens to everyone.

Try it

Deleting a branch only peels off its label. The commits stay for a while. The reflog: Git's diary of everywhere HEAD has been. remembers them.

Tap the line with your about page commit.

~/diary $ git reflog

0 of 1 found

Try it

Stick a new about label on that commit.

6d3a9b1a8feb63270a76e140649c

Predict

What does git branch -D really delete?

Pick one answer.

Check

Prevent it next time. Sort each fact.

Drag a card into a box. Or tap the card, then tap the box.

      You did it!

      You can now bring back a branch you deleted by mistake.

      Go deeper (optional)

      Look back at the hook. Git printed the old hash after the word was. git branch about plus that hash works too. Deleted the branch on GitHub as well? Its pull request page can often restore it.