This will unstage all files you might have staged with git add
:
(这将取消您使用git add
暂存的所有文件:)
git reset
This will revert all local uncommitted changes (should be executed in repo root):
(这将还原所有本地未提交的更改(应在repo root中执行):)
git checkout .
You can also revert uncommitted changes only to particular file or directory:
(您还可以仅将未提交的更改还原到特定文件或目录:)
git checkout [some_dir|file.txt]
Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):
(还原所有未提交更改的另一种方法(更长时间键入,但可以从任何子目录工作):)
git reset --hard HEAD
This will remove all local untracked files, so only git tracked files remain:
(这将删除所有本地未跟踪文件,因此只保留git跟踪文件:)
git clean -fdx
WARNING: -x
will also remove all ignored files, including ones specified by .gitignore
!
(警告: -x
还将删除所有被忽略的文件,包括.gitignore
指定的文件!)
You may want to use -n
for preview of files to be deleted. (您可能希望使用-n
来预览要删除的文件。)
To sum it up: executing commands below is basically equivalent to fresh git clone
from original source (but it does not re-download anything, so is much faster):
(总结一下:执行下面的命令基本上相当于来自原始源的新git clone
(但它不会重新下载任何内容,因此速度更快):)
git reset
git checkout .
git clean -fdx
Typical usage for this would be in build scripts, when you must make sure that your tree is absolutely clean - does not have any modifications or locally created object files or build artefacts, and you want to make it work very fast and to not re-clone whole repository every single time.
(这种情况的典型用法是在构建脚本中,当你必须确保你的树是绝对干净的 - 没有任何修改或本地创建的目标文件或构建工件,并且你想让它工作得非常快而且不能重新每次都克隆整个存储库。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…