Reputation: 4984
I accidentally did git pull
instead of git push
and got a merge conflict. I was surprised that git tried a merge at all, because the remote branch didn't receive any commits since my last pull/push. Since I didn't want to do a pull/merge, I did git reset --hard
followed by git merge --abort
. I tried to push, but got the message:
On branch my_branch
Your branch and 'origin/my_branch' have diverged,
and have 17 and 1 different commit each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
How can I get back to the state before the accidental pull to be able to push my local commits to the remote branch?
Upvotes: 0
Views: 185
Reputation: 37832
your remote did get a commit pushed. You can have a look at the git tree using this command:
git log --all --graph --decorate --oneline
maybe you did a git commit --amend
or something like that on the one commit that is already on the remote. Analyse the output of the command above (and post it maybe in your question) to see which commit you want to keep.
Since you are working on your personal branch, you might consider (note that this is not ideal) to crush your (1) remote commit with your (17) local commits, using
git push -f
WARNING: in this case you will "lose" that one remote commit.
If you want to keep that one remote commit, you might consider first rebasing your local work onto that commit, before pushing
git rebase origin/my_branch
git push
Upvotes: 1