如何从当前 Git 工作树中删除本地(未跟踪)文件 [英] How to remove local (untracked) files from the current Git working tree

查看:23
本文介绍了如何从当前 Git 工作树中删除本地(未跟踪)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从当前工作树中删除未跟踪的本地文件?

How do you delete untracked local files from your current working tree?

推荐答案

git-clean - 从工作树中删除未跟踪的文件

概要

git-clean - Remove untracked files from the working tree

Synopsis

git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>…​

说明

通过递归删除不受版本控制的文件来清理工作树,从当前目录开始.

通常只删除 Git 未知的文件,但如果指定了 -x 选项,忽略的文件也会被删除.例如,这对于删除所有构建产品很有用.

Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. This can, for example, be useful to remove all build products.

如果给出了任何可选的 ... 参数,则只有那些路径会受到影响.

If any optional <path>... arguments are given, only those paths are affected.


第 1 步是使用 -n 选项显示将要删除的内容:


Step 1 is to show what will be deleted by using the -n option:

# 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

  • 要删除目录,请运行 git clean -f -dgit clean -fd
  • 要删除被忽略的文件,请运行 git clean -f -Xgit clean -fX
  • 要删除忽略和未忽略的文件,请运行 git clean -f -xgit clean -fx
    • To remove directories, run git clean -f -d or git clean -fd
    • To remove ignored files, run git clean -f -X or git clean -fX
    • To remove ignored and non-ignored files, run git clean -f -x or git clean -fx
    • 注意后面两个命令的X的大小写差异.

      Note the case difference on the X for the two latter commands.

      如果 clean.requireForce 设置为true"(默认)在您的配置中,需要指定 -f 否则实际上什么都不会发生.

      If clean.requireForce is set to "true" (the default) in your configuration, one needs to specify -f otherwise nothing will actually happen.

      再次查看 git-clean 文档了解更多信息信息.

      Again see the git-clean docs for more information.

      -f, --force

      Options

      -f, --force

      如果 Git 配置变量 clean.requireForce 没有设置为false,除非给定 -f-n-i,否则 git clean 将拒绝运行.

      If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f, -n or -i.

      -x

      不要使用从 .gitignore 读取的标准忽略规则(每directory) 和 $GIT_DIR/info/exclude,但仍然使用 ignore-e 选项给出的规则.这允许删除所有未跟踪的文件,包括构建产品.这可以使用(可能结合使用 git reset) 创建一个原始的工作目录来测试一个干净的构建.

      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

      仅删除 Git 忽略的文件.这可能对重建有用一切从头开始,但保留手动创建的文件.

      Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.

      -n, --dry-run

      -n, --dry-run

      实际上不要删除任何内容,只需显示将要执行的操作.

      Don’t actually remove anything, just show what would be done.

      -d

      除未跟踪的文件外,还删除未跟踪的目录.如果未跟踪的目录由不同的 Git 存储库管理,它是默认不删除.如果你真的想使用 -f 选项两次删除这样的目录.

      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.

      这篇关于如何从当前 Git 工作树中删除本地(未跟踪)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆