Git:删除untracked files

原文地址:https://stackoverflow.com/questions/61212/how-to-remove-local-untracked-files-from-the-current-git-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 -fotherwise 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.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 约摸一个月前的八月,坐火车回成都,到终点站下火车时已是晚上八点半了。出站的人是脚跟紧脚尖的,没见着空隙。我也在这人...
    木寸村阅读 2,738评论 0 0
  • 清明,我国的传统节日,周四周五周六三天放假;周日上班。国人大多会在这个节日回家扫墓祭祖。 有了昨晚...
    慕海春阅读 1,170评论 0 0
  • 几乎是我所见过的最可怕的面试了。刷新了我的三观。几乎没一个回答上来。 自我介绍 手写HashMap 听到问题懵逼了...
    __Kirito_阅读 7,546评论 2 0
  • “有句话,不知当讲不当讲。” “那你就别讲了。” “不,我还是要说!” “……” 如果真呼吁男女平等的话,我觉得,...
    安妮阿尼哟阅读 981评论 0 0
  • 这个周看完了维克多 ·弗兰克尔 的《man's search for meaning 活出生命的意义》让我...
    瑛姐Zoe阅读 2,713评论 2 3