在 git 中最后一次提交后重置所有更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4630312/
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
Reset all changes after last commit in git
提问by Dogbert
How can I undo everychange made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?
如何撤消上次提交后对目录所做的所有更改,包括删除添加的文件、重置修改过的文件和添加回已删除的文件?
回答by Benjamin Bannier
First reset the changes
首先重置更改
git reset HEAD --hard
then clean out everything untracked. If you want to keep files that are not tracked due to .gitignore
, be careful with this command.
然后清除所有未跟踪的内容。如果要保留由于 未跟踪的文件,请.gitignore
小心使用此命令。
git clean -fd
回答by Ortomala Lokni
How can I undo every changemade to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?
如何撤消上次提交后对目录所做的所有更改,包括删除添加的文件、重置修改过的文件和添加回已删除的文件?
You can undo changes to trackedfiles with:
git reset HEAD --hard
You can remove untrackedfiles with:
git clean -f
You can remove untrackedfiles and directories with:
git clean -fd
but you can't undo change to untracked files.
You can remove ignored and untrackedfiles and directories
git clean -fdx
but you can't undo change to ignored files.
您可以使用以下命令撤消对跟踪文件的更改:
git reset HEAD --hard
您可以使用以下方法删除未跟踪的文件:
git clean -f
您可以使用以下命令删除未跟踪的文件和目录:
git clean -fd
但您无法撤消对未跟踪文件的更改。
您可以删除被忽略和未跟踪的文件和目录
git clean -fdx
但您无法撤消对忽略文件的更改。
You can also set clean.requireForce
to false
:
您还可以设置clean.requireForce
为false
:
git config --global --add clean.requireForce false
to avoid using -f
(--force
) when you use git clean
.
避免在使用时使用-f
( --force
) git clean
。