git 将本地 repo 重置为与远程 repo 完全相同

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

Reset local repo to be exactly the same as remote repo

git

提问by James

How do I reset my local git repo to be exactly the same as the remote repo?

如何将我的本地 git repo 重置为与远程 repo 完全相同?

I've tried:

我试过了:

git reset --hard HEAD^

But now git statussays I have diverging commits. I basically want to just wipe anything I've got locally and get the exact remote repo on my local machine.

但现在git status说我有不同的提交。我基本上只想擦除我在本地拥有的任何东西,并在我的本地机器上获取确切的远程存储库。

回答by CharlesB

git reset --hard HEAD^will only reset your working copy to the previous (parent) commit. Instead, you want to run

git reset --hard HEAD^只会将您的工作副本重置为之前的(父)提交。相反,你想跑

git reset --hard origin/master

Assuming remote is originand the branch you want to reset to is master

假设远程是origin并且您要重置的分支是master

回答by Sailesh

You could delete the current branch, and create the branch again at the remote/branchname commit

您可以删除当前分支,并在远程/分支名称提交处再次创建分支

git branch -D branchname
git checkout remote/branchname
git branch branchname