Crap! About a week ago, I was rebasing some commits while trying to clean up my repository, and apparently I didn't actually finish it. Today, a week and several commits later, I went to rebase to reorder a few commits from today, and it told me I was already in the middle of a rebase.
That should have been a cue to copy my repo just in case. But I did not...instead I ran git rebase --abort
which sounded right at the time. Well, that was not right. It aborted the rebase from a week ago and reset master's HEAD to the old one. Dummy!
I've got several other branches that are fairly recent, and I've pushed to remote several times, but the most recent changes appear to be gone forever. I don't possess the appropriate level of git-fu to know if there's any way to recover my changes.
Am I screwed?
EDIT - WOW! Thanks guys! git reflog
is awesome! I'm fully recovered...lesson learned. Marking Tchalvak's answer accepted for being the first to post.
You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called. You can run git rebase --skip to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included.
To undo the rebase , we can use the reflog command of Git. Using git reflog , we can determine the branch's head commit immediately before the rebase starts.
The purpose of rebase is make your commits look as if they were changes to the branch you rebase onto. So the most logical way is to incorporate merge conflicts into these commits. No additional commits is required thus.
Check git reflog
. You can walk back in time using those commit hashes as a reference in almost all cases.
I'd also physically copy the git repo directory elsewhere as a place to do preliminary testing to see what will work, that way you can mess with whatever you want without losing untracked files or getting things into a state that you can't come back from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With