.gitignore 中的文件不會被忽略

.gitignore 中的文件不會被忽略

如標題所示,我在儲存庫的 .gitignore 檔案中放置了一個檔案路徑...但是當該檔案發生變更(自動發生)時,我在運行時會看到它git status

~/.dotfiles (master)✹ ᐅ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   home_stuff/.config/rofi/theme.rasi

no changes added to commit (use "git add" and/or "git commit -a")

這是我在 .gitignore 檔案中的輸入: home_stuff/.config/rofi/theme.rasi

那是怎麼回事?

答案1

有時需要從快取中刪除先前追蹤的檔案才能正常運作。你應該能夠用這 3 個指令來解決這個問題。

git rm -r -cached . (從追蹤中刪除快取和所有檔案。)

git add .(添加回您的文件,沒有將被忽略的文件)

git commit (提交新文件)

答案2

已被 Git 追蹤的檔案不受影響。

這在描述的第二行中有說明。https://git-scm.com/docs/gitignore

要停止追蹤目前正在追蹤的文件,請使用 git rm --cached。

相關內容