當我們的項目文件已經(jīng)存在于git索引中時,即使添加了.gitignore,我們依然能在git的工作樹追蹤中看到指定忽略了的文件。這時我們就需要如下操作:
為了避免沖突,先pull遠程倉庫到本地
$ git pull
刪除本地項目目錄的緩存
$ git rm -r --cached .
新建或網(wǎng)絡(luò)down下.gitignore文件
$ touch .gitignore
$ vi .gitignore
再次add倉庫路徑下的所有文件
$ git add .
再次執(zhí)行commit命令
$ git commit -m "add .gitignore"
最后,提交到遠程倉庫
$ git push