.gitignore是Git工具的配置文件,用於屏蔽某些文件上傳到線上。git
一、建立.gitignore
項目路徑下添加.gitignore文件緩存
touch .gitignore
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
二、編輯.gitignore文件,創建下面的規則
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
三、建立個test文件, git status 測試是否忽略
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
git status
已經忽略test文件工具
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
配置無效幾種狀況
- 命令格式錯誤
- 在配置語句的先後面添加空格、Tab、註釋等,會致使當前行的配置語句失效
- 配置語句對已經add、commit的文件無效(.gitignore只能忽略原來沒有被追蹤的文件,如已被歸入了版本管理中,則修改.gitignore是無效的。)
第三種狀況解決辦法:刪除本地緩存測試
git rm -r --cached .
git add .
git commit -m 'update .gitignore'