0

I am new to git and pretty confused by this.

I accidentally pulled the wrong branch into the branch I was working on, so I searched and found git reset --hard is meant to pull it back to the original state. I did this, but nothing happened - the files I pulled remain.

I then used git reflog show to see if I could do something like git reset --hard HEAD@{1} but none of the repos listed are the one I am working on.

Would anyone be able to help me just reverse this accidental pull?

3 Answers 3

1

If you want to reset your branch to branch master instead of wrong-branch.

Note that this will blow away any changes you had on branch master that you did not push to the remote.

# fetch from remote to make sure you have all latest changes git fetch origin # reset to the correct branch git reset --hard origin/master 
Sign up to request clarification or add additional context in comments.

Comments

0

You should specify the hash of commit that you want to restor something like

git reset --hard [<commit>] 

Comments

0

Because you have merged the origin/wrong-branch to your local branch(e.g br), so the head is changed.

If you didn't change anything in local branch, you can just reset to origin/br

git reset --hard origin/br 

or you need to find the commit hash before you pull, and then reset to it

git reset --hard <commitHash> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.