简体   繁体   中英

git: Reverting to my remote branch and discarding all commits locally?

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM