Git取消配置文件的跟踪

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WMSOK/article/details/79654253

一般我们都是通过.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

猜你喜欢

转载自blog.csdn.net/WMSOK/article/details/79654253
今日推荐