我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
要删除未跟踪的文件 :
git add .
git reset --hard HEAD
其他回答
我喜欢用git stash
命令,稍后您可以得到隐藏的文件和更改。git clean
这也是一个很好的选择, 但完全取决于您的要求。 这是关于 Git 藏藏和 Git 干净的解释,7.3 Git 工具 - 粉刷和清洁
使用使用git clean -f -d
以确保目录目录目录目录也删除。
不要删除任何东西, 只显示会做什么。
git clean -n
或
git clean --dry-run
除未跟踪的文件外,删除未跟踪的目录。如果一个未跟踪的目录由不同的 Git 仓库管理,则默认不会删除。使用该目录。
-f
如果您真的想要删除此目录, 选项将两次 。git clean -fd
然后您可以检查您的文件是否真的已删除git status
.
更好的方法就是使用:干净干净
git clean -d -x -f
这将删除未跟踪的文件, 包括目录(-d)
被git (-x)
.
另替换-f
参数和-n
要执行 a/dry-run
或-i
用于交互式模式,它将告诉您要删除什么。
git clean -f -d -x $(git rev-parse --show-cdup)
对根目录应用干净, 无论您在仓库目录树中将其命名为哪里。 我总是使用它, 因为它不会迫使您离开您现在工作所在的文件夹, 并允许您从所在位置清除并承诺 。
确定该旗帜-f
, -d
, -x
匹配您的需要 :
-d
Remove untracked directories in addition to untracked files. If an
untracked directory is managed by a different Git repository, it is
not removed by default. Use -f option twice if you really want to
remove such a directory.
-f, --force
If the Git configuration variable clean.requireForce is not set to
false, git clean will refuse to delete files or directories unless
given -f, -n or -i. Git will refuse to delete directories with .git
sub directory or file unless a second -f is given. This affects
also git submodules where the storage area of the removed submodule
under .git/modules/ is not removed until -f is given twice.
-x
Don't use the standard ignore rules read from .gitignore (per
directory) and $GIT_DIR/info/exclude, but do still use the ignore
rules given with -e options. This allows removing all untracked
files, including build products. This can be used (possibly in
conjunction with git reset) to create a pristine working directory
to test a clean build.
还有其他的旗帜 也有其他的,只是检查git clean --help
.
git clean -f to remove untracked files from working directory.
我在博客上报导了一些基本内容,git- intro- 基本命令
推荐文章
- 如何在过去的一些任意提交之间注入一个提交?
- 从GitHub克隆项目后拉git子模块
- GitHub上的分叉和克隆有什么区别?
- 递归地按模式添加文件
- 我如何使用notepad++(或其他)与msysgit?
- 如何将现有的解决方案从Visual Studio 2013添加到GitHub
- Git存储库中的悬垂提交和blob是什么?它们来自哪里?
- 我如何简单地从我最新的git提交创建一个补丁?
- Git显示“警告:永久添加到已知主机列表”
- 我如何检索一个回购的远程git地址?
- 如何列出提交,因为某些提交?
- 如何在不位于存储库的情况下执行Git命令?
- 为什么git在Windows下记不住我的密码
- 我如何得到bash完成工作与别名?
- 组合多个git存储库