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

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

问题描述

如何从当前工作树中删除未跟踪的本地文件? 根据Git文档 git clean


从工作树中移除未跟踪的文件






第1步是显示通过使用 -n 选项删除:

  git clean -n 

清理步骤 - 注意:这会删除文件

  git clean -f 




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

  • 要删除被忽略的文件,运行 git clean -f -X git clean -fX
  • code>
  • 要删除忽略和不被忽略的文件,请运行 git clean -f -x git clean -fx



注意后两个命令的 X 的案例区别。



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



请再次参阅 git-clean 文档以获取更多信息。



选项



-f

- 强制


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



-x 仍然使用-e选项提供的忽略规则。这允许删除所有未跟踪的文件,包括构建产品。这可以使用(可能与git reset一起)创建一个纯净的工作目录来测试一个干净的版本。



-X



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



-n



- 空运

不要实际移除任何内容,只显示将要完成的操作。



-d



除未追踪的文件外,还删除未追踪的目录。如果未跟踪的目录由不同的Git存储库管理,则默认情况下不会删除它。使用-f选项两次,如果你真的想删除这样一个目录。


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

解决方案

As per the Git Documentation git clean

Remove untracked files from the working tree


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

git clean -n

Clean Step - beware: this will delete files:

git clean -f

  • 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

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

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

Again see the git-clean docs for more information.

Options

-f

--force

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

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

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

-n

--dry-run

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

-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.

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

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