如何从当前工作树中删除未追踪的本地文件?
当前回答
使用 git reset HEAD <file> 删除文件
其他回答
用途: git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x♰ -X] [--]...
-q, --quiet do not print names of files removed
-n, --dry-run dry run
-f, --force force
-i, --interactive interactive cleaning
-d remove whole directories
-e, --exclude <pattern>
add <pattern> to ignore rules
-x remove ignored files, too
-X remove only ignored files
我很惊讶以前没有人提到这一点:
git clean -i
它是互动的,你会得到一个快速的概述,什么将被删除,为您提供包含 / 排除受影响的文件的可能性。
你必須在 -d 如果你也想照顧空的文件夾。
git iclean
说到这一点,对互动命令的额外持有可能令人兴奋的经验丰富的用户,如今我只使用已经提到的 git clean -fd
在运行清洁命令之前,总是使用 -n,因为它会向您展示哪些文件会被删除。
通常情况下,当没有确定的情况下,Git Clean 不会返回未跟踪的目录,以避免删除太多。 指定 -d 以便返回此类目录。 如果任何路径是确定的, -d 是无关紧要的; 所有未跟踪的文件符合确定的路径(除非在 --force 中提到的未跟踪的Git目录)将被删除。
git clean -n -d
git clean -n -d -f
git clean -d -f
默认情况下, git clean 只会删除未追踪的文件,这些文件不会被忽视. 任何符合您的.gitignore 或其他 ignore 文件中的模式的文件将不会被删除. 如果您想要删除这些文件,您可以将 -x 添加到清洁命令。
git clean -f -d -x
git clean -x -i
If you are not 100% sure that deleting your uncommitted work is safe, you could use stashing instead
git stash --all
git stash push --keep-index
呼叫 git stash 没有任何论点,相当于 git stash push。
git stash push -m "name your stash" // before git stash save (deprecated)
git stash drop // or clean
要查看关于如何使用 stash 的完整指示,请参见此 如何在 git 中以名称命名和获取 stash?
要删除未追踪的文件:
git add .
git reset --hard HEAD
git-clean - 从工作树中删除未追踪的文件 同步 git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x♰ -X] [--] <path>... 描述 通过从当前目录开始,不受版本控制的文件重新删除工作树。
# Print out the list of files and directories which will be removed (dry run)
git clean -n -d
# Delete the files from the repository
git clean -f
注意后两个命令的 X 中的案例差异。
推荐文章
- 如何点Go模块的依赖在Go。Mod到回购中的最新提交?
- 为什么调用git分支——unset-upstream来修复?
- Windows git“警告:LF将被CRLF取代”,这是警告尾巴向后吗?
- git中的哈希冲突
- git可以自动在空格和制表符之间切换吗?
- Git暂存文件列表
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时