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.
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> .
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.
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.
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