0

Can anyone help, i have my local branch which i did a pull from my remote and then i have just done about 7 commits and they are all wrong :-)

So what i want to do is revert to my remote branch copy.

I don't want to create another branch, i am happy with the name "master", is there no UNDO feature that says PULL and disregard everything locally?

Currently my local branch Master is 6 commits ahead of the my remote origin, i want to revert my local branch Master to the same as my origin master.

Thanks in advance

Martin
  • 23,844
  • 55
  • 201
  • 327

2 Answers2

1

Many ways to Rome. Probably the easiest thing you can do is to first fetch from your remote (just making sure your remote pointer is really where your remote is) and then just reset your local branch to it.

git fetch origin 
git reset --hard origin/master
Christoph
  • 26,519
  • 28
  • 95
  • 133
  • This works great, but a little problem, i have already PUSHED it to the remote. so now when i do the changes and do a PUSH it tells me to a PULL first which adds the old commit messages back :-( I know its dangerous to change soemthing thats on a remote but i know nobody has branched it or anything... Is there a way round this... – Martin Aug 15 '12 at 15:21
  • Currently my local branch master NOW is perfect with you changes but the remote has the old comments in :-( – Martin Aug 15 '12 at 15:22
  • It makes no sense. If you did what I wrote both branches will be identical. Whatever, if you really want to override the remote branch you can do that with: git push -f origin master – Christoph Aug 15 '12 at 15:29
  • Hi Christoph, no they were not identical... but doing a -f sorted it - perfect thanks – Martin Aug 15 '12 at 21:18
0

git reset --hard HEAD~6 will wipe out the top 6 commits. (that is, it will set master to the current head's 6th ancestor, then clear your working tree and index. The commits will still exist until git-gc garbage-collects them)

AI0867
  • 376
  • 4
  • 11