7

I started a git rebase in my repository a day ago and never finished it. I forgot about and did a lot of modifications while I was still in the rebase. Today I accidentally did a git rebase --abort without putting those modifications in a commit. Now it looks like all my modifications are gone. Is there any way to recover them?

My git reflog looks like this:

57d731c HEAD@{0}: rebase: aborting
d2d3738 HEAD@{1}: rebase -i (start): checkout david
57d731c HEAD@{2}: commit: My commit message
3
  • 2
    Have a look at git reflog and see if you can find your edited commits :) Commented Apr 25, 2016 at 19:55
  • So you suggest if I checkout d2d3738 it would restore the uncommited modifications I did during the rebase? Commented Apr 25, 2016 at 19:58
  • 1
    Use git show or git log -p (or gitk) to inspect the commit in question. If you didn't commit the changes though, chances are slim. I don't think Git will auto-stash them when aborting a rebase. Worth a try might also be checking for dangling blobs and trees which could contain the versions of your files you lost. Commented Apr 25, 2016 at 20:07

4 Answers 4

5

You can only recover if you have added the content even if you did not commit. But if you did not even added the changes to the staging are you cannot recover those changes unless you use IDE and the IDE has local history of your changes.

git start to track file once they are in the stage area and not while they are untracked.

The local history exists in all the majors IDEs.

Sign up to request clarification or add additional context in comments.

5 Comments

Local IDE history for the win!
I staged my changes before aborting the old rebase but still can't recover them.
Does Xcode have this? (Or do you mean the undo history?)
This. git reflog couldn't help me, but luckily I sitll had the files open on VSC, so a bunch of Ctrl+Zs did the trick.
@dwenaus Thanks man. saved me lots of efforts. recovered from vscode local history
4

If you didn't commit those modifications during the rebase, they unfortunately will be irrevocably lost.

1 Comment

I'd like to add that git only takes full responsibility for your data when you commit. It's unfortunate that you have lost work, but there's a lesson to be learned here: try to commit often to avoid this situation in the future. Cheers!
2

It's better to use git stash before git rebase. git stash pop can easily take you where you were.

Comments

1

you can checkout to the commit you want after doing a reflog.

git checkout 57d731c 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.