Orphaned commits after rebase
Quick summary
You rebased and the original pre-rebase commits are now orphaned — they exist in the object store but no branch or tag points to them.
Why this happens
git rebase creates new commits with different hashes, leaving the original commits unreachable from any ref
You did not save the original branch position before rebasing, so no ref keeps the old commits alive
git gc pruned the orphaned commits after the reflog expired, making them permanently unrecoverable
Minimal example
git rebase main # original commits now orphaned
git gc --prune=now # orphaned commits permanently lostgit branch backup-before-rebase # preserve original commits
git rebase main # original commits safe in backup branchCreating a backup branch before rebasing ensures the original commits remain reachable and will not be pruned by garbage collection.
How to diagnose
Run git reflog to find the original pre-rebase HEAD and verify the orphaned commits are still in the object store
Use git fsck --lost-found to list dangling commits that are not reachable from any branch or tag
Check git log --oneline --all to confirm the old commits do not appear in any reachable branch history
How to fix
Create a branch pointing to the pre-rebase state with git branch backup-pre-rebase ORIG_HEAD to preserve the original commits
Recover from reflog with git cherry-pick <old-commit-hash> if specific original commits need to be restored
If commits were pruned by gc, recover from a remote that still has them with git fetch origin <commit-hash>
How to prevent
Always create a backup branch before rebasing with git branch backup-$(date +%s) to preserve the original commits
Increase reflog expiry with git config gc.reflogExpire '365 days' to keep orphaned commits recoverable for longer
Related Resources
Related Lessons
- git rebase
Learn about rebasing safely.