Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undo git pull of wrong branch onto master

Tags:

I have pulled from a different branch from the remote. The 2 branches are different yet the merge happened silently on my current branch. I am currently working on the "master" branch locally, and it has been updated with the changes of the remote branch - "FE_Changes".

How do I remove the effects of the "FE_Changes" branch from my master branch ?

like image 962
OverTheEdge Avatar asked Feb 24 '15 12:02

OverTheEdge


People also ask

How do I revert a git pull from another branch?

There is no command to explicitly undo the git pull command. The alternative is to use git reset, which reverts a repository back to a previous commit.

How do I revert a git pull request?

Under your repository name, click Pull requests. In the "Pull Requests" list, click the pull request you'd like to revert. Near the bottom of the pull request, click Revert.


2 Answers

git reset --hard HEAD~1

This will nuke the most recent commit on your local branch. Assuming your pull strategy is merge, then there should only be one rogue commit on your local master branch. You mentioned that "the merge happened silently," so this should work in your case. Once you have fixed the master branch, you may pull again, this time making sure you pull from the correct remote branch.

like image 177
Tim Biegeleisen Avatar answered Sep 27 '22 22:09

Tim Biegeleisen


In addition to Tim's answer: If you want to reset to a specific commit:

git reflog 

will show you ids of all recent commits

enter image description here

Then you can perform:

git reset --hard <specific id> 

to reset to that specific commit.

like image 21
saurabh Avatar answered Sep 27 '22 21:09

saurabh