git - 如何 git clean 手动创建的文件

标签 git

是否可以(无需再次进行 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 时,它还会删除未跟踪/忽略的目录

另请参阅http://git-scm.com/docs/git-clean

关于git - 如何 git clean 手动创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28896926/

相关文章:

git - saltstack 项目的存储库结构

git - [用户名].github.io 遇到问题

windows - Git (TortoiseGit) - 如何将单个文件恢复到以前的修订版,然后撤消恢复?

git - 为特定文件选择 Git merge 策略 ("ours", "mine", "theirs")

linux - 移动 .git 目录而不移动文件

git p4 : migrate full history - including integration history

node.js - git status 没有显示我更改的文件

git - 从 Git 存储中查找并提取文件

git - github ReadMe.md 在同一产品的不同主分支中可以不同吗?

git - 'git status' 显示来自 origin/master 的错误提交计数