How to undo a last pull and commit

Viewed 62

I mistakenly pulled a master branch in to develop branch and committed some changes.

I want to revert the pull and the commit.

I tried this command

git revert <commit hash>

but it gives me following error

commit <commit hash> is a merge but no -m option was given.

How to revert a pull and commit?

2 Answers

git revert is not what you need here, despite the colloquial sense of the word "revert".

Instead, you'd rather reset the branch to the point where it was before the bad pull :

git checkout develop
git reset --hard @{upstream}

where @{upstream} is a construct which means "at upstream, as in the remote branch this one is configured to pull from".

You won't have to --force anything after this, since you're not changing history, rather sticking back to it.

Run this command.

git reset --keep e2djke3 #your commit id

This variant is more safer. Then you commit your changes as usual

Related