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

查看:122
本文介绍了如何从当前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.

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

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






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

# Print out the list of files which will be removed (dry run)
git clean -n

清理步骤-当心:这将删除文件

# Delete the files from the repository
git clean -f




  • 要删除目录,请运行 git clean -f -d git clean -fd

  • 删除忽略的文件,运行 git clean -f -X git clean -fX

  • 要删除被忽略和未被忽略的文件,请运行 git clean -f -x git 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

      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

      -x

      不要使用从.gitignore(每个
      目录)和 $ GIT_DIR / info / exclude 中读取的标准忽略规则,但仍使用- 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

      -X

      仅删除Git忽略的文件。从头开始重建
      的所有内容可能很有用,但保留手动创建的文件。

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

      -n -空运行

      -n, --dry-run

      实际上并未删除任何内容,只是显示

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

      -d

      -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天全站免登陆