当我有.gitignore data/*并运行时git clean -fd,数据文件夹及其所有内容文件将被删除.
我想要的是删除git仓库中所有未经检查的文件,同时排除所有被忽略的文件(即不要删除gitignored文件).我能做什么?
我在使用 git clean 和排除嵌套目录选项时遇到问题。
我想清除存储库中除vendor/bundle目录之外的所有未提交的文件。我的测试仓库看起来像:
debugg-dir/
.git/
file.txt
not-commited-file
not-commited-folder
another-not-commited-file
vendor/
bundle/
another-not-commited-file
Run Code Online (Sandbox Code Playgroud)
使用以下命令重现测试存储库:
git init debugg-dir && cd debugg-dir
touch file.txt && g add . && git commit -m "Commit"
mkdir -p not-commited-folder && touch not-commited-folder/another-not-commited-file
mkdir -p vendor/bundle && touch vendor/bundle/another-not-commited-file && touch not-commited-file
Run Code Online (Sandbox Code Playgroud)
Git 清理命令:
git clean -d -x -n -e vendor/bundle
Run Code Online (Sandbox Code Playgroud)
清洁后预计有:
debugg-dir/
.git/
file.txt
vendor/
bundle/
another-not-commited-file
Run Code Online (Sandbox Code Playgroud)
有没有正确的方法可以从 git clean 命令中排除嵌套目录?
# 编辑:
解释:
对于这种情况没有“干净”的解决方案。Git clean 排除了 with 的目录git clean -d …