git Git混淆 - 如何将本地更改恢复到最新的远程推送?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12845507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git confusion - how to revert local changes to latest remote push?
提问by user1738984
I have a local git repository, but things get wrong and complicated and I simply want to overwrite all the files in my local directory with the latest version of what is on the remote repository. This would be like a clone, but for an already setup local git repository.
我有一个本地 git 存储库,但事情变得错误且复杂,我只想用远程存储库上的最新版本覆盖本地目录中的所有文件。这就像一个克隆,但对于已经设置的本地 git 存储库。
For example: if use git pull
, then I don't get locally deleted folders back from the remote.
例如:如果使用git pull
,那么我不会从远程取回本地删除的文件夹。
Is it checkout
that I must use? But how to tell it to retrieve the files from a remote (and not from the stage) and overwrite all?
是checkout
我必须使用的吗?但是如何告诉它从远程(而不是从舞台)检索文件并覆盖所有文件?
回答by Brian Phillips
You probably want to use git reset
. Assuming you have done a git fetch
recently, the following will discard everything in your local and reset it to the point you specify as the final argument (in this case the current HEAD of the origin/master
remote tracking branch):
您可能想要使用git reset
. 假设您git fetch
最近做了一个,以下将丢弃您本地的所有内容并将其重置为您指定为最终参数的点(在这种情况下是origin/master
远程跟踪分支的当前 HEAD ):
$ git reset --hard origin/master