如何从当前工作树中删除未追踪的本地文件?
当前回答
如果需要从特定子目录中删除未追踪的文件,
git clean -f {dir_path}
并结合的方式来删除未追踪的Dir/文件和被忽略的文件。
git clean -fxd {dir_path}
此后,您将仅在 git 状态中修改文件。
其他回答
git-clean 是你正在寻找的,它被用来从工作树中删除未追踪的文件。
要知道在实际删除之前会删除什么:
清洁 -d -n
它会产生这样的东西:
将移除 sample.txt
要删除前命令输出中列出的所有内容:
清洁 -d -f
它会产生这样的东西:
删除 sample.txt
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 add .
git stash
更多信息 https://www.atlassian.com/git/tutorials/saving-changes/git-stash#stashing-your-work
如果没有其他工作,可以使用下列组合来简单地删除“吉特状态”命令列出的所有变化:
git add -A& git commit -m temp && git reset --hard HEAD^
这将首先完成您的所有变化,然后创建一个暂时的承诺,然后放弃它。
推荐文章
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件
- Git错误:遇到7个文件应该是指针,但不是