git放弃所有更改并从上游拉出 [英] git discard all changes and pull from upstream

查看:76
本文介绍了git放弃所有更改并从上游拉出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获取上游回购并使其替代母版?我的仓库中只有一个分支,即主分支,并且完全弄乱了它,因此我基本上需要从上游重新开始.我认为init可以完成工作,但是有没有更简单的方法?

How do I fetch upstream repo and make it replace master? I only have one branch on my repo, which is master, and I completely messed it up, so I basically need to start over from the upstream. I think init will do the job, but is there an easier way?

推荐答案

(至少)您可以在这里做两件事–您可以重新克隆远程仓库,或者可以reset --hard到共同祖先,然后再做拉,它将快速前进到远程主服务器上的最新提交.

There are (at least) two things you can do here–you can reclone the remote repo, or you can reset --hard to the common ancestor and then do a pull, which will fast-forward to the latest commit on the remote master.

具体来说,这是Nevik Rehnel原始答案的简单扩展:

To be concrete, here's a simple extension of Nevik Rehnel's original answer:

git reset --hard origin/master
git pull origin master

注意:使用git reset --hard会丢弃所有未提交的更改,如果您是git的新手,可能会很容易将自己与该命令混淆,因此请确保您对什么有所了解它会在继续之前完成.

NOTE: using git reset --hard will discard any uncommitted changes, and it can be easy to confuse yourself with this command if you're new to git, so make sure you have a sense of what it is going to do before proceeding.

这篇关于git放弃所有更改并从上游拉出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆