忽略跟蹤檔案中的更改。存根
.gitignore 和 .git/info/exclude
僅適用於未跟蹤的檔案。
要在跟蹤的檔案上設定 ignore 標誌,請使用命令 update-index :
git update-index --skip-worktree myfile.c
要恢復此功能,請使用:
git update-index --no-skip-worktree myfile.c
你可以將此程式碼段新增到全域性 git 配置中, 以便更方便地使用 git hide
,git unhide
和 git hidden
命令:
[alias]
hide = update-index --skip-worktree
unhide = update-index --no-skip-worktree
hidden = "!git ls-files -v | grep ^[hsS] | cut -c 3-"
你還可以使用選項 –assume-unchanged 和 update-index 函式
git update-index --assume-unchanged <file>
如果要再次檢視此檔案以進行更改,請使用
git update-index --no-assume-unchanged <file>
當指定了 –assume-unchanged 標誌時,使用者承諾不更改檔案,並允許 Git 假設工作樹檔案與索引中記錄的檔案匹配。如果需要在索引中修改此檔案,Git 將失敗例如,在提交中合併; 因此,如果上游更改了假定未跟蹤檔案,則需要手動處理該情況。在這種情況下,重點在於效能。
雖然 –skip-worktree 標誌在指示 git 不接觸特定檔案時很有用,因為該檔案將在本地更改,並且你不希望意外提交更改(即為特定檔案配置的配置/屬性檔案)環境)。當兩者都設定時,Skip-worktree 優先於假設未更改。