你可能不知道的git clean


git clean是干啥的?

git clean可以帮你清理workspace中未被git版本控制的文件,比如临时文件,构建出来的二进制文件。

使用方法

如果你的clean.requireForce项没有设置为false,那么每次使用git clean时都要加上-f参数

示例如下,workspace中有2个调试logo时创建的临时png文件,commit之前需要删掉。如果不用git clean的话需要一个一个rm。

LM-SHC-00355679@17:42:26:~/Angular/pomodoro-time (master)
=> git status -s ?? image/logo1.png ?? image/logo2.png 

使用git clean可以快速清楚,当临时文件较多时尤其方便。

LM-SHC-00355679@17:42:30:~/Angular/pomodoro-time (master)
=> git clean -f Removing image/logo1.png Removing image/logo2.png 

有的时候可能需要将当前workspace打包成zip。但是直接打包会将.gitignore里的文件也打进去。这是git clean也可以帮忙。只需加上-x参数。

LM-SHC-00355679@17:48:13:~/Angular/pomodoro-time (master)
=> cat .gitignore 
/coverage
LM-SHC-00355679@17:48:16:~/Angular/pomodoro-time (master) # -d 参数表示连同目录一起删除 => git clean -xfd Removing coverage/ LM-SHC-00355679@17:48:25:~/Angular/pomodoro-time (master) => ls coverage ls: coverage: No such file or directory 

以上就是git clean的基本用法啦。下面介绍下git clean的其他可选参数:

  • -n 并不实际执行删除操作,只显示出将被清理的文件列表
  • -X 仅删除.gitignore里标记过的文件,那些既不被git版本控制,又不在.gitignore中的文件会被保留。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM