作用
?在Git的項目中編寫.gitignore文件可以忽略Git中不想提交的文件。
以配置文件setting.properties模擬
新建文件 echo nul->setting.properties
此時git status
On branch new_branch //在new_branch分支上
Untracked files: //為追蹤的文件
(use "git add <file>..." to include in what will be committed)//可以使用add命令去添加需被提交的文件
setting.properties //為追蹤的文件
nothing added to commit but untracked files present (use "git add" to track)//沒有修改去提交但是存在未追蹤的文件
新建文件 echo nul->.gitignore
此時git status
On branch new_branch //在new_branch上
Untracked files: //未追蹤的文件
(use "git add <file>..." to include in what will be committed)//可以使用add命令去添加需要被提交的文件
.gitignore
setting.properties
nothing added to commit but untracked files present (use "git add" to track) //沒有修改將要提交(暫存區(qū)沒有修改信息),但是存在未追蹤的文件
我們需要setting.properties文件不被git版本控制系統(tǒng)監(jiān)控-----忽略
在.gitignore中添加setting.properties文件
vi .gitignore文件
按i進(jìn)入插入模式,輸入setting.properties,按ESC進(jìn)入命令模式,輸入:wq 回車
此時git status
On branch new_branch //在new_branch分支上
Untracked files://未追蹤的文件
(use "git add <file>..." to include in what will be committed)
.gitignore //需添加的文件
nothing added to commit but untracked files present (use "git add" to track)
//此時setting.properties已經(jīng)在需追蹤的文件中 取消(就是忽略了)
忽略規(guī)則
?空行或者#號開頭的行,是無效行/注釋行
?以斜杠“/”開頭表示目錄
?以星號“*”通配多個字符
?以問號“?”通配單個字符
?以嘆號“!”表示取反