git update-index
git
用法
git update-index [--skip-worktree|--chmod=+x] <file>直接改动索引;这些标记只在本地、不会被推送,而想保留自己对已跟踪配置文件的改动,该用 --skip-worktree 而不是 --assume-unchanged。
常用选项
| 选项 | 含义 |
|---|---|
| --chmod=+x | record the executable bit, useful from Windows |
| --skip-worktree | let you keep local edits to a tracked file |
| --no-skip-worktree | undo that |
| --assume-unchanged | promise you will not edit it, as a speed hint only |
| --no-assume-unchanged | undo that |
| --refresh | update stat information after a filesystem change |
示例
git update-index --chmod=+x scripts/deploy.shstages the executable bit so CI can run it
git update-index --skip-worktree config/local.jsonkeeps your local edits out of every diff
git update-index --no-skip-worktree config/local.jsonputs 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