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的其他可选参数: