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中的文件會被保留。