Back to lessons

Hosting Operations

Branch a Recovered Commit

You found a useful discarded commit in reflog and need to preserve it with a branch name.

Command

cd /lab/git-recovery-rollback && git branch recovered-incident-note HEAD@{1}

What changed

A local branch named recovered-incident-note is created inside the disposable demo repository.

Danger

caution

When to use it

Use when a reflog entry contains work you may need to inspect, cherry-pick, or restore later.

When not to use it

Do not create branches from reflog entries you have not inspected if the repository contains sensitive or unrelated work.

Undo or recovery

Delete the local branch with git branch -D recovered-incident-note inside the demo repo.

Expected output

The new branch points at the recovered incident note commit.

demo script

Disposable terminal steps

  1. cd /lab/git-recovery-rollback && git show -s --format='%h %s' HEAD@{1}
  2. cd /lab/git-recovery-rollback && git branch recovered-incident-note HEAD@{1}
  3. cd /lab/git-recovery-rollback && git log --oneline recovered-incident-note -1

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ cd /lab/git-recovery-rollback && git show -s --format='%h %s' HEAD@{1}
7e5872b Capture incident rollback note
::exit-code::0
$ cd /lab/git-recovery-rollback && git branch recovered-incident-note HEAD@{1}
::exit-code::0
$ cd /lab/git-recovery-rollback && git log --oneline recovered-incident-note -1
7e5872b Capture incident rollback note
::exit-code::0

YouTube Short

Save the reflog commit.

Once you find the lost commit, branch it. A branch name is easier to review than a temporary reflog selector.

LinkedIn hook

Put a name on the reflog commit before it slips away.

Question: When you find lost work in reflog, do you branch it immediately?

experiments

A/B tests to run

Metric: save_rate

A: Put a name on recovered work.

B: Reflog finds it, branch preserves it.