Repository navigation
URGENT Help! Lost commits after failed rebase - how to recover? #14515
Replies: 3 comments 4 replies
|
@gemadhavi To recover your work, you need to find the last commit you made before the rebase started. Since your code isn't pushed, git reflog is your only map.
Verify the code: Restore the branch:
Why use --stat? It shows line counts (+500/-0) so you can identify the right commit without reading 500 lines of diff. Search by code: If you know a unique function name you wrote, find its commit with: If this solution helped you, please mark it as an approved answer to help others |
|
Hey @gemadhu! Reading this gave me terrible flashbacks. Staring at 60 raw lines of text from git reflog right after losing 500 lines of code is a uniquely terrible flavor of developer panic. While the accepted answer above gives you the perfect underlying Git CLI commands, I actually just built a lightweight, open-source terminal app for this exact scenario because I was so frustrated by how overwhelming git reflog text walls are. It's called git-time-machine. Instead of juggling hashes on a sticky note and running git show a dozen times, it gives you a clean visual UI over your reflog. You just scroll up and down with your arrow keys to see the timeline, press / to instantly search the reflog for words you know you wrote, and just hit Enter to restore your code. If this ever happens again (and hopefully it doesn't!), it might make the recovery process take 5 seconds instead of an hour of stress. Glad you got your code back! |

Hey @gemadhu! No, it's completely free and open source. Here are the exact steps to recover your code:
Step 1: Install it
If you have Rust/Cargo installed:
cargo install git-time-machine
If you don't have Rust, you can install it first with:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Step 2: Run it from your repo folder
Open your terminal, cd into the repo where you lost the commits, and run:
git-time-machine --all
The --all flag is important in your case since you have 60+ reflog entries. It will load all of them into the visual timeline.
Step 3: Find your lost commit
You'll see a scrollable list of every action Git recorded. Use the arrow keys (or j/k) to scroll thro…