Git:如何覆盖本地更改?

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

Git: How to overwrite local change?

gitrestore

提问by mlzboy

I use git clone from github and I deleted some files & modified some files. Now I want to keep my local code & restore to the original form. Is there a command to achieve this?

我使用来自 github 的 git clone 并删除了一些文件并修改了一些文件。现在我想保留我的本地代码并恢复到原始形式。有没有命令可以实现这一目标?

回答by seriyPS

If you want to save you changes first, you can commit them before and then checkout you code to previous commit(s): git checkout HEAD^(one commit back) git checkout GEAD~2(2 commits back)

如果您想先保存更改,您可以先提交它们,然后将代码签出到之前的提交:( git checkout HEAD^返回一次提交) git checkout GEAD~2(返回 2 次提交)

Or, if you don't need your changes anymore, run git reset --hard HEAD

或者,如果您不再需要更改,请运行 git reset --hard HEAD

回答by Nick Moore

git checkout <name of file>

git checkout <name of file>

If you want to check out the whole repository, then from the root directory use

如果要检出整个存储库,则从根目录使用

git checkout .

git checkout .

回答by James Gregory

git reset --hard

git reset --hard

回答by Mradula Ghatiya

Git command to pull all changes from branch by overwriting all local changes:-

通过覆盖所有本地更改来从分支中提取所有更改的 Git 命令:-

git reset --hard HEAD
git pull

回答by Abdul Majeed

You can remove local changes by this command

您可以通过此命令删除本地更改

git clean -f

and pull changes by:

并通过以下方式拉动更改:

git pull