Maintenance

Recover Lost Git Work with Reflog and Safe References

Use reflog and backup references to recover commits after resets, rebases, and branch changes.

Git often retains references to recent branch positions even after a commit becomes unreachable from a named branch. The reflog can help recover work, but it should be used carefully.

Inspect before changing state

Use git status, inspect branch history, and review the reflog to locate the prior commit. Reflog entries describe where references pointed; they do not guarantee that every object will be retained indefinitely.

Create a recovery branch

Once the likely commit is identified, create a new branch pointing to it before attempting further cleanup. This gives the recovered work a stable reference and makes it easier to inspect the diff.

Avoid premature garbage collection

Do not run aggressive cleanup commands while investigating lost work. If important data is missing, stop making changes and preserve the repository copy before attempting recovery.

Checklist

  • Inspect reflog entries and commit details.
  • Create a branch at the recovered commit.
  • Review the recovered diff before merging.
  • Avoid cleanup during recovery.
  • Improve backup and branch practices to prevent recurrence.
Share this page Help other developers discover this resource.