简体   繁体   English

git:恢复到我的远程分支并在本地丢弃所有提交?

[英]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 :-) 谁能帮忙,我有我的本地分支,我从遥控器上拉了一个,然后我刚完成了大约7次提交,它们都错了:-)

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? 我不想创建另一个分支,我对“ master”这个名称感到满意,是否没有UNDO功能会显示PULL并忽略本地所有内容?

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. 目前,我的本地分支母版比我的远程原点要早6个提交,我想将我的本地分支母版还原为与我的原始母版相同。

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. git reset --hard HEAD~6将清除前6个提交。 (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) (也就是说,它将master设置为当前head的第6个祖先,然后清除您的工作树和索引。这些提交将一直存在,直到git-gc对其进行垃圾收集为止)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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