git reset --hard origin/master 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15432052/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:45:21  来源:igfitidea点击:

What is the meaning of git reset --hard origin/master?

gitversion-controlgit-reset

提问by Raza

I did a git pulland got an error:

我做git pull了一个错误:

The following working tree files would be overwritten by merge... Please move or remove them before you can merge.

以下工作树文件将被合并覆盖...请在合并之前移动或删除它们。

To resolve this I did the following:

为了解决这个问题,我做了以下事情:

git fetch
git reset --hard origin/master

Now when I do git pull, it says everything up to date. I want to know what exactly happens when I run these commands. I know git fetchfetches the changes from the remote repo without merging them into my local repo.

现在,当我这样做时git pull,它说明一切都是最新的。我想知道运行这些命令时到底发生了什么。我知道git fetch从远程仓库获取更改而不将它们合并到我的本地仓库中。

What is the meaning of git reset --hard origin/master? How does it work?

是什么意思git reset --hard origin/master?它是如何工作的?

回答by CB Bailey

git reset --hard origin/master

says: throw away all my staged and unstaged changes, forget everything on my current local branch and make it exactly the same as origin/master.

说:扔掉我所有已暂存和未暂存的更改,忘记我当前本地分支上的所有内容,并使其与origin/master.

You probably wanted to ask this before you ran the command. The destructive nature is hinted at by using the same words as in "hard reset".

您可能想在运行命令之前询问这个问题。通过使用与“硬重置”中相同的词来暗示破坏性。