[git] git gitignore 不生效 not work 如何忽略已經提交的文件

  • 5683
  • 0
  • git
  • 2020-04-07

[git] git gitignore 不生效 not work

  • gitignore的檔案若已經commit的話,gitignore並不會生效,目前git也沒有automatic去清除,必須手動清除cache
    • 刪除在.gitgnore中的檔案:以下二擇一,或是您使用sourcetree直接右鍵取消追蹤即可
      • ​git rm -r --cached .
      • git rm --cached `git ls-files -i --exclude-from=.gitignore`​​
    • 新增所以刪除的檔案到commit區
      • git add .
    • 新增一個commit即可
      • git commit -m "fixed untracked files"​
    • git push origin <branch-name> 後,遠端repo上的檔案也會隨之移除
  • ​其他來源