如何从当前工作树中删除未追踪的本地文件?
当前回答
git clean -fd 删除目录
git clean -fX 删除被忽略的文件
git clean -fx 删除被忽略和未被忽略的文件
可以使用上述所有选项,如
清洁 -fdXx
查看 git 手册 获取更多帮助
其他回答
git-clean 是你正在寻找的,它被用来从工作树中删除未追踪的文件。
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
注意: 首先,导航到目录并检查您要清理的分支。
-i 互动模式,它会告诉你什么将被删除,你可以从列表中选择一个操作。
清理文件只有 [文件不会列出并不会清理]: $ git clean -i 清理文件和文件夹: $ git clean -d -i
D 包括目录。
如果您从列表中选择 c 将删除未跟踪的文件/文件夹,并将删除您删除的文件/文件夹。
例如: 如果您在远程中重组文件夹并将更改拖到本地计算机上,则由其他人创建的文件/文件夹将最初在过去的文件夹和您重组的新文件夹中。
我用这个:
git 状态 复制文件路径 rm <文件路径>
我的项目有很多由一个巨大的 ANT 构建脚本创建的创建文件,使用 git clean 会产生混乱。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式