michael
michael

Reputation: 110710

How can I revert my changes using 'git pull'?

I did a 'git pull' instead of a 'git pull --rebase'.

SHA: 138937298d80a7c84d0630b1db509ca2596aca91  // top of my git

<< some changes I got from 'git pull' >>
SHA:

SHA:
<< end of some changes I got from 'git pull' >>

SHA: 08ebb55902e206a30d6f344b4684bd525970dda3  // my original top of my git before i do anything.

My question is how can I revert the changes I got from 'git pull' and then I do a 'git pull --rebase' ?

Another question is I am using 'gitx' on Mac, the changes I got from 'git pull' are on a different vertical line and the ones I originally have. Why is that? Thank you.

Upvotes: 4

Views: 2277

Answers (2)

Jonathan
Jonathan

Reputation: 13624

Let's say you're on master and you want to pull in remote changes to origin/master and rebase your work onto the "official" branch, but you made a mistake:

git pull origin

Now you've got a merge of your work and the stuff from the server; that's not what you wanted!

git stash save
git reset --hard HEAD@{1}
git stash apply

Now you're back where you were before the pull, but you still want to put your changes on top of what was on the server...

git rebase origin/master

There you go, all set!

Upvotes: 1

poke
poke

Reputation: 388403

Find the other HEAD you want to revert to using git reflog and then reset to the commit. Usually, if you didn't do anything after the pull, this would be git reset --hard HEAD@{1}

Upvotes: 3

Related Questions