Git取消配置檔案的跟蹤
阿新 • • 發佈:2019-02-10
一般我們都是通過.gitignore檔案來現實commit時不提交一編譯中間檔案。但.gitignore有個缺點,即當之前該檔案已經被跟蹤(track),那麼再把這個檔名新增到.gitignore中就沒有用了。
不過網上有很多文章說,通過以下命令讓.gitignore生效:
git rm -rf --cache xxx.h
但執行完該命令,再commit的時候發現remote上的該檔案被刪除了。如果我們需要繼續保留該檔案,只是不提交當前的change,該怎麼辦了?比如應用的一些配置檔案,初始化的配置檔案需要當然要在remote上存在的,但不希望我們個人的配置資訊push到remote上。
此時,就需要以下命令來實現了(暫時取消config.ini跟蹤):
認為未改變
git update-index --assume-unchanged config.ini
取消認為未改變
git update-index --no-assume-unchanged config.ini
附:
$ git update-index -help
usage: git update-index [<options>] [--] [<file>...]
-q continue refresh even when index needs update
--ignore-submodules refresh: ignore submodules
--add do not ignore new files
--replace let files replace directories and vice-versa
--remove notice files missing from worktree
--unmerged refresh even if index contains unmerged entries
--refresh refresh stat information
--really-refresh like --refresh, but ignore assume-unchanged setting
--cacheinfo <mode>,<object>,<path>
add the specified entry to the index
--chmod (+/-)x override the executable bit of the listed files
--assume-unchanged mark files as "not changing"
--no-assume-unchanged
clear assumed-unchanged bit
--skip-worktree mark files as "index-only"
--no-skip-worktree clear skip-worktree bit
--info-only add to index only; do not add content to object database
--force-remove remove named paths even if present in worktree
-z with --stdin: input lines are terminated by null bytes
--stdin read list of paths to be updated from standard input
--index-info add entries from standard input to the index
--unresolve repopulate stages #2 and #3 for the listed paths
-g, --again only update entries that differ from HEAD
--ignore-missing ignore files missing from worktree
--verbose report actions to standard output
--clear-resolve-undo (for porcelains) forget saved unresolved conflicts
--index-version <n> write index in this format
--split-index enable or disable split index
--untracked-cache enable/disable untracked cache
--test-untracked-cache
test if the filesystem supports untracked cache
--force-untracked-cache
enable untracked cache without testing the filesystem