Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: restore diverged repository after failed rebase

Tags:

git

merge

rebase

I ran a git pull --rebase, and aborted this after fixing several merge-conflicts using git rebase --abort.

Before the attempted rebase, git status told me: "Your branch is ahead of 'origin/master' by 20 commits." Now I get: "Your branch and 'origin/master' have diverged, and have 15 and 5 different commit(s) each, respectively."

I have already done a reset to the latest commit (git reset --hard c15...e30), but the status message is still the same.

How do I revert my repository to the state is was before I started the mess? And what is the difference between the current state and the previous?

Thanks.

like image 785
Josh_E_L Avatar asked Oct 18 '10 14:10

Josh_E_L


People also ask

How do I reset a diverged branch?

Sometimes a branch has diverged from origin so much, that it doesn't make sense to try to resolve all the conflicts. In this case, it's better to just reset your local branch to whatever is on origin. To do this, you need to fetch first and then run git reset --hard origin/<branch> .

How do I fix the divergent branches in git?

warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull: git config pull. rebase false # merge (the default strategy) git config pull. rebase true # rebase git config pull.


1 Answers

The git rebase --abort should have taken you back to your original HEAD. I'm not sure what you meant by "fixing several merge-conflicts using ... abort". Did you mean --continue?

Anyway, the thing to do now is consult the reflog. The reflog is a local, temporal log of where all of your references have been. If you look at .git/logs/HEAD you can see where HEAD (the working set) has been. Under .git/logs/refs/... you can see where all of your branches (local and remote) have been. Each line in the log reflects some action. The starting SHA, ending, user, time, and a string describing what action caused the change. You can find the one you want and reset back to it.

like image 75
Ben Jackson Avatar answered Oct 09 '22 11:10

Ben Jackson