是否可以(无需再次进行 git 克隆)通过 repo 进入“干净”状态,手动创建的文件也会被删除?
我有一个 gitignored 的目录:
# .gitignore
mydir/
目录 mydir 已手动创建并包含文件。当我做一个
git clean -X -f .
在我的存储库的基本目录中,mydir 未被删除。这似乎与文档一致,我们可以看到 here 。
我现在的问题是:清理我的存储库的最佳方法是什么?我可以rm -rf
我的存储库,然后运行git clone
,但也许有一个“更好”的方法来做到这一点?
最佳答案
您正在寻找 -d
标志
-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.
和-x
标志
-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.
当您同时使用 -x
和 -d
执行 $ git clean -xdf
时,它还会删除未跟踪/忽略的目录
关于git - 如何 git clean 手动创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28896926/