使用 git,如何将本地部署分支重置为 origin 的版本?

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

With git, how do I reset the local deployment branch to origin's version?

git

提问by Tom

I've got a local branch called deployment. This branch is also on origin. How do I reset the local deployment branch to the state of origin's deployment branch?

我有一个名为deployment. 这个分支也在origin。如何将本地部署分支重置为 的部署分支的状态origin

Something like the following:

类似于以下内容:

git fetch origin
git reset --hard origin/deployment

Would that be possible?

那可能吗?

采纳答案by Mark Longair

That's correct, but be careful - git reset --hardthrows away alluncommitted changes, i.e. those just in your working tree or the index (staging area). Also, just make sure that you really are on the deploymentbranch with git checkout deployment, since git resetalways changes the position of the current branch, i.e. the one that HEADpoints to.

这是正确的,但要小心 -git reset --hard丢弃所有未提交的更改,即那些只是在您的工作树或索引(暂存区)中的更改。另外,只需确保您确实在deployment带有的分支上git checkout deployment,因为git reset总是会更改当前分支的位置,即HEAD指向的位置。