Git pull into wrong branch

Viewed 45038

Myself and one other developer had been merging and pushing our work to a non-master branch called toolwork. That way, we didn't impact the rest of the team. My topic branch was called DPM-93 and my git workflow was this.

# do some work
git checkout DPM-93
git commit -m "did some work"

# catch up
git checkout toolwork
git pull origin toolwork

# rebase my topic branch
git checkout DPM-93
git rebase toolwork

# merge and push my changes
git checkout toolwork
git merge --no-ff DPM-93
git push origin toolwork

That was mostly working fine until I accidently issued these git commands

git checkout toolwork
git pull origin master

At that point, a bunch of new stuff showed up in branch toolwork and I'm not sure how to get rid of it short of deleting my workspace and re-cloning from the repo.

Is there any way to back this out to the state before the pull?

7 Answers

What worked for me is simply

git reset --hard

I did this from the local repository with the unfortunate merge/pull:

Laptop@LAPTOP-xxxxxxxx /d/Google Drive/xxxxxxx/Github/xxxxx (staging_ec2|MERGING)
$ git reset --hard
HEAD is now at 2d5a511 [last commit comment]

Laptop@LAPTOP-xxxxxxxx /d/Google Drive/xxxxxxx/Github/xxxxx (staging_ec2)
$

Step 1:

git log

git reset --hard <hash>, 
  

The hash is something like 0928817nsbn78867hs3g5666

Example: if you git log, you will get:

commit 0928817nsbn78867hs3g5666 (HEAD -> yourrepo, origin/yourrepo)

Step 2:

git reset --hard 0928817nsbn78867hs3g5666

You can abort that merge using below command

git merge --abort

It will simply undo the accidental pull...

Related