git索引包含的是什么? [英] What does the git index contain EXACTLY?
问题描述
Git索引究竟包含了什么,以及我可以使用什么命令来查看索引的内容?
更新
感谢您的所有答案。我知道索引作为一个暂存区,索引中的内容是索引而不是工作树。我只是很好奇索引对象的组成。我想这可能是一个文件名/目录名称列表,SHA-1对,一种虚拟树可能?
在Git术语中,有没有 plumbing 命令可以列出索引的内容?
在包含哪些索引:
索引是一个二进制文件(通常保存在
.git / index
中),其中包含路径名的有序列表,每个路径名都有权限和SHA1一个斑点物体;git ls-files
可以显示索引的内容:
$ git ls-files --stage
100644 63c918c667fa005ff12ad89437f2fdc80926e21c 0 .gitignore
100644 5529b198e8d14decbe4ad99db3f7fb632de0439d 0 .mailmap
Racy git问题给出了有关该结构的更多详细信息:
索引是最重要的数据结构之一in git。
它通过记录路径及其对象名称列表来表示一个虚拟工作树状态,并作为暂存区域来写出要提交的下一个树对象。
状态是虚拟的,因为它不一定非得与工作树中的文件匹配。
要了解更多信息,请参阅参考资料。 git / git / Documentation / technical / index -format.txt :
Git索引文件格式如下
< blockquote>
所有二进制数字都是网络字节顺序。
Version 2 在这里描述,除非另有说明。
- 包含以下内容的12字节标题:
- 4字节签名 :
签名是{'D
','I
','R
','C
'}(代表dircache
) - 4字节版本号:
当前支持的版本为2,3和4。 / li>
- 32位索引条目数。
- 4字节签名 :
- 大量排序的 index entries 。 扩展 :
扩展是通过签名来标识的。
如果Git不理解它们,可以忽略可选的扩展名。
Git当前支持缓存树并解析撤消扩展。
- 4字节的扩展签名。如果第一个字节是'
A
'..'Z
',那么扩展名是可选的,可以忽略。 li>
- 扩展名的32位大小
- 扩展名数据
- 160位SHA-1覆盖索引文件的内容。
mljrg $ b
如果索引是下一个提交准备好的地方,为什么?
由于索引代表正在被跟踪的内容,并且在提交之后,被跟踪的内容与上次提交相同(
git diff --cached
不返回任何内容)。
$ b所以
git ls-files -s
列出所有追踪的文件(对象名称,模式位和阶段编号输出)。
$ b该列表(跟踪的元素)使用提交的内容进行初始化。
当您切换分支时,索引内容为重置为您刚切换到的分支引用的提交。What does the Git index exactly contain, and what command can I use to view the content of the index?
Update
Thanks for all your answers. I know that the index acts as a staging area, and what is committed is in the index rather than the working tree. I am just curious about what an index object consists of. I guess it might be a list of filename/directory name, SHA-1 pairs, a kind of virtual tree maybe?
Is there, in Git terminology, any plumbing command that I can use to list the contents of the index?
解决方案The Git book contains an article on what an index includes:
The index is a binary file (generally kept in
.git/index
) containing a sorted list of path names, each with permissions and the SHA1 of a blob object;git ls-files
can show you the contents of the index:$ git ls-files --stage 100644 63c918c667fa005ff12ad89437f2fdc80926e21c 0 .gitignore 100644 5529b198e8d14decbe4ad99db3f7fb632de0439d 0 .mailmap
The Racy git problem gives some more details on that structure:
The index is one of the most important data structures in git.
It represents a virtual working tree state by recording list of paths and their object names and serves as a staging area to write out the next tree object to be committed.
The state is "virtual" in the sense that it does not necessarily have to, and often does not, match the files in the working tree.
To see more, cf. "git/git/Documentation/technical/index-format.txt":
The Git index file has the following format
All binary numbers are in network byte order.
Version 2 is described here unless stated otherwise.- A 12-byte header consisting of:
- 4-byte signature:
The signature is { 'D
', 'I
', 'R
', 'C
' } (stands for "dircache
") - 4-byte version number:
The current supported versions are 2, 3 and 4. - 32-bit number of index entries.
- 4-byte signature:
- A number of sorted index entries.
- Extensions:
Extensions are identified by signature.
Optional extensions can be ignored if Git does not understand them.
Git currently supports cached tree and resolve undo extensions.- 4-byte extension signature. If the first byte is '
A
'..'Z
' the extension is optional and can be ignored. - 32-bit size of the extension
- Extension data
- 4-byte extension signature. If the first byte is '
- 160-bit SHA-1 over the content of the index file before this checksum.
If the index is the place where the next commit is prepared, why doesn't "
git ls-files -s
" return nothing after commit?Because the index represents what is being tracked, and right after a commit, what is being tracked is identical to the last commit (
git diff --cached
returns nothing).So
git ls-files -s
lists all files tracked (object name, mode bits and stage number in the output).That list (of element tracked) is initialized with the content of a commit.
When you switch branch, the index content is reset to the commit referenced by the branch you just switched to.这篇关于git索引包含的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 4字节的扩展签名。如果第一个字节是'