首页·终端命令

git update-index

git

用法

git update-index [--skip-worktree|--chmod=+x] <file>

直接改动索引;这些标记只在本地、不会被推送,而想保留自己对已跟踪配置文件的改动,该用 --skip-worktree 而不是 --assume-unchanged。

常用选项

选项含义
--chmod=+xrecord the executable bit, useful from Windows
--skip-worktreelet you keep local edits to a tracked file
--no-skip-worktreeundo that
--assume-unchangedpromise you will not edit it, as a speed hint only
--no-assume-unchangedundo that
--refreshupdate stat information after a filesystem change

示例

git update-index --chmod=+x scripts/deploy.sh

stages the executable bit so CI can run it

git update-index --skip-worktree config/local.json

keeps your local edits out of every diff

git update-index --no-skip-worktree config/local.json

puts the file back under normal tracking

难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. git update-index 是做什么的?

直接改动索引;这些标记只在本地、不会被推送,而想保留自己对已跟踪配置文件的改动,该用 --skip-worktree 而不是 --assume-unchanged。

Q. 怎么写?

git update-index [--skip-worktree|--chmod=+x] <file> —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 6 个,完整列表在 man git。这条命令属于git。

相关命令

man 手册: man git-update-index