git-update-index命令

通常该命令用于将工作区(working tree)中的内容注册到暂存区(index)

命令格式

git update-index
[–add] [–remove | –force-remove] [–replace]
[–refresh] [-q] [–unmerged] [–ignore-missing]
[(–cacheinfo <mode>,<object>,<file>)…​]
[–chmod=(+|-)x]
[–[no-]assume-unchanged]
[–[no-]skip-worktree]
[–[no-]fsmonitor-valid]
[–ignore-submodules]
[–[no-]split-index]
[–[no-|test-|force-]untracked-cache]
[–[no-]fsmonitor]
[–really-refresh] [–unresolve] [–again | -g]
[–info-only] [–index-info]
[-z] [–stdin] [–index-version <n>]
[–verbose]
[–] [<file>…​]

命令参数选项

  • –add: 如果指定的文件不在暂存区(index)中,则将其加入暂存区。

例子

增加工作区新文件到暂存区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@localhost git_update_index]# git init
Initialized empty Git repository in /root/git_update_index/.git/
[root@localhost git_update_index]# find .git/objects/ -type f
[root@localhost git_update_index]# echo 'version 1' > text.txt
[root@localhost git_update_index]# git status
On branch master

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)

text.txt

nothing added to commit but untracked files present (use "git add" to track)
[root@localhost git_update_index]# git update-index --add text.txt
[root@localhost git_update_index]# git status
On branch master

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: text.txt

[root@localhost git_update_index]# find .git/objects/ -type f
.git/objects/83/baae61804e65cc73a7201a7252750c76066a30
[root@localhost git_update_index]# git cat-file -p 83baae6
version 1