Git索引到底包含什么,我可以使用什么命令来查看索引的内容?
谢谢你的回答。我知道索引作为一个暂存区,提交的内容在索引中而不是工作树中。我只是好奇一个索引对象由什么组成。我猜它可能是一个文件名/目录名列表,SHA-1对,一种虚拟树?
在Git术语中,是否有任何可以用来列出索引内容的管道命令?
Git索引到底包含什么,我可以使用什么命令来查看索引的内容?
谢谢你的回答。我知道索引作为一个暂存区,提交的内容在索引中而不是工作树中。我只是好奇一个索引对象由什么组成。我猜它可能是一个文件名/目录名列表,SHA-1对,一种虚拟树?
在Git术语中,是否有任何可以用来列出索引内容的管道命令?
当前回答
这是你真正需要的,使用这个命令。
$ binwalk指数
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
1717 0x6B5 Unix path: /company/user/user/delete.php
1813 0x715 Unix path: /company/user/user/get.php
1909 0x775 Unix path: /company/user/user/post.php
2005 0x7D5 Unix path: /company/user/user/put.php
3373 0xD2D Unix path: /urban-airship/channel/channel/post.php
3789 0xECD Unix path: /urban-airship/named-user/named-user/post.php
3901 0xF3D Unix path: /user/categories/categories/delete.php
4005 0xFA5 Unix path: /user/categories/categories/get.php
4109 0x100D Unix path: /user/categories/categories/put.php
4309 0x10D5 Unix path: /user/favorites/favorites/delete.php
其他回答
Git索引是工作目录和存储库之间的临时区域。您可以使用索引构建一组希望一起提交的更改。创建提交时,提交的是当前在这个索引中的内容,而不是工作目录中的内容。
要查看索引内的内容,发出命令:
git status
当您运行git status时,您可以看到哪些文件是暂存的(当前在您的索引中),哪些文件已被修改但尚未暂存,以及哪些文件完全未被跟踪。
你可以看看这个。谷歌搜索会抛出许多链接,这些链接应该是相当自给自足的。
Git书中包含了一篇关于索引包含什么的文章:
索引是一个二进制文件(通常保存在.git/index中),包含一个排序的路径名列表,每个路径名都有权限和一个blob对象的SHA1;Git ls-files可以显示索引的内容:
$ git ls-files --stage
100644 63c918c667fa005ff12ad89437f2fdc80926e21c 0 .gitignore
100644 5529b198e8d14decbe4ad99db3f7fb632de0439d 0 .mailmap
Racy git问题给出了该结构的更多细节:
索引是git中最重要的数据结构之一。 它通过记录路径列表及其对象名称来表示一个虚拟工作树状态,并作为一个staging区域来写出要提交的下一个树对象。 这个状态是“虚拟的”,因为它不需要匹配工作树中的文件,通常也不匹配。
2021年11月:参见Derrick Stolee (Microsoft/GitHub)的“用Git的稀疏索引让你的单库存感觉很小”
The Git index is a critical data structure in Git. It serves as the “staging area” between the files you have on your filesystem and your commit history. When you run git add, the files from your working directory are hashed and stored as objects in the index, leading them to be “staged changes”. When you run git commit, the staged changes as stored in the index are used to create that new commit. When you run git checkout, Git takes the data from a commit and writes it to the working directory and the index. In addition to storing your staged changes, the index also stores filesystem information about your working directory. This helps Git report changed files more quickly.
要了解更多,请参阅。“git / git /文档/技术/ index-format.txt”:
Git索引文件的格式如下
所有二进制数都是网络字节顺序。 除非另有说明,这里描述的是版本2。
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. 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 160-bit SHA-1 over the content of the index file before this checksum.
mljrg评论:
如果索引是下一次提交准备的地方,为什么"git ls-files -s"在提交后不返回任何东西?
因为索引表示被跟踪的内容,并且在提交之后,被跟踪的内容与上次提交是相同的(git diff——cached不返回任何内容)。
所以git ls-files -s列出了所有跟踪的文件(输出中的对象名称,模式位和阶段号)。
该列表(跟踪的元素)由提交的内容初始化。 切换分支时,索引内容被重置为刚才切换到的分支引用的提交。
Git 2.20(2018年Q4)添加了一个索引项偏移表(IEOT):
参见Ben Peart (benpeart)的commit 77ff112, commit 3255089, commit abb4bb8, commit c780b9c, commit 3b1d9e0, commit 371ed0d(2018年10月10日)。 参见提交252d079(2018年9月26日)由nguyThái ngeconc Duy (pclouds)。 (由Junio C Hamano—gitster—在commit e27bfaa中合并,2018年10月19日)
ieot:添加ieot (Index Entry Offset Table)扩展
This patch enables addressing the CPU cost of loading the index by adding additional data to the index that will allow us to efficiently multi- thread the loading and conversion of cache entries. It accomplishes this by adding an (optional) index extension that is a table of offsets to blocks of cache entries in the index file. To make this work for V4 indexes, when writing the cache entries, it periodically"resets" the prefix-compression by encoding the current entry as if the path name for the previous entry is completely different and saves the offset of that entry in the IEOT. Basically, with V4 indexes, it generates offsets into blocks of prefix-compressed entries.
用新的索引。线程配置设置,索引加载现在更快。
作为(使用IEOT)的结果,提交7bd9631清理Git 2.23(2019年Q3)的read-cache.c load_cache_entres_threading()函数。
参见Jeff King (peff)的commit 8373037、commit d713e88、commit d92349d、commit 113c29a、commit c95fc72、commit 7a2a721、commit c016579、commit be27fb7、commit 13a1781、commit 7bd9631、commit 3c1dce8、commit cf7a901、commit d64db5b、commit 76a7bc0(2019年5月9日)。 (由Junio C Hamano—gitster—在commit c0e78f7中合并,2019年6月13日)
Read-cache:从线程加载中删除未使用的参数
load_cache_entries_threading()函数的作用是:带src_offset参数 它不使用。自77ff112 (read-cache:在工作线程上加载缓存项,2018-10-10,Git v2.20.0-rc0)开始时就存在了。 在邮件列表中,该参数是该系列早期迭代的一部分,但当代码切换到使用IEOT扩展时,就不需要了。
在Git 2.29 (Q4 2020)中,格式描述调整为最近的SHA-256工作。
参见commit 8afa50a, commit 0756e61, commit 123712b, commit 5b6422a (15 Aug 2020) by Martin Ågren (none)。 (由Junio C Hamano—gitster—在commit 74a395c中合并,2020年8月19日)
index-format.txt:文件SHA-256索引格式 署名:Martin Ågren
在SHA-1存储库中,我们使用SHA-1,在SHA-256存储库中,我们使用SHA-256,然后用更中性的东西取代“SHA-1”的所有其他用途。 避免引用“160位”哈希值。
技术/索引格式现在包括在它的手册页:
所有二进制数都是网络字节顺序。 在使用传统SHA-1的存储库中,校验和和对象id (对象名)都是使用SHA-1计算的。 类似地,在SHA-256存储库中,这些值是使用SHA-256计算的。 除非另有说明,这里描述的是版本2。
在回应@ciro-santilli-%e9%83%9d%e6%b5%b7% 4%b8%9c%e5%86% a07 %8a%b6% 97% 855 %85%ad%e5%9b%9b%e4%ba%8b%e4%bb%b6% b3% 95b %e5% e5%8a%9f的指数,am分享输出为其中一个TODO。
如果你添加,那么阶段0将被添加到该路径的索引中,git将知道冲突已被标记为已解决。托朵:检查这个。”
更具体地说,是不同的合并阶段。
0:普通文件,不存在合并冲突 1:基础 2:我们的 3:他们的
关于各个阶段的详细数字表示,在这种情况下一个文件有冲突。
$ git ls-files -s
100644 f72d68f0d10f6efdb8adc8553a1df9c0444a0bec 0 vars/buildComponent.groovy
$ git stash list
stash@{0}: WIP on master: c40172e turn off notifications, temporarily
$ git stash apply
Auto-merging vars/commonUtils.groovy
Auto-merging vars/buildComponent.groovy
CONFLICT (content): Merge conflict in vars/buildComponent.groovy
$ git ls-files -s
100644 bc48727339d36f5d54e14081f8357a0168f4c665 1 vars/buildComponent.groovy
100644 f72d68f0d10f6efdb8adc8553a1df9c0444a0bec 2 vars/buildComponent.groovy
100644 24dd5be1783633bbb049b35fc01e8e88facb20e2 3 vars/buildComponent.groovy
我只是想让那个混蛋上擂台。
索引是git中最重要的数据结构之一。 它通过记录路径列表及其对象名称来表示一个虚拟工作树状态,并作为一个staging区域来写出要提交的下一个树对象。 这个状态是“虚拟的”,因为它不需要匹配工作树中的文件,通常也不匹配。
如果我签出一个特殊的提交,git ls-tree会准确地告诉我应该呈现哪些工作文件/对象吗?在ls-tree中,我们说的是哪种树?
例子
git ls-tree -r -l HEAD
git ls-tree -r -l commit-hash
顺便说一句:ls-tree也适用于不签出(-n)克隆的存储库,其中ls-files不返回任何内容。
https://stackoverflow.com/a/56242906/2623045
https://stackoverflow.com/a/67567058/2623045
这是你真正需要的,使用这个命令。
$ binwalk指数
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
1717 0x6B5 Unix path: /company/user/user/delete.php
1813 0x715 Unix path: /company/user/user/get.php
1909 0x775 Unix path: /company/user/user/post.php
2005 0x7D5 Unix path: /company/user/user/put.php
3373 0xD2D Unix path: /urban-airship/channel/channel/post.php
3789 0xECD Unix path: /urban-airship/named-user/named-user/post.php
3901 0xF3D Unix path: /user/categories/categories/delete.php
4005 0xFA5 Unix path: /user/categories/categories/get.php
4109 0x100D Unix path: /user/categories/categories/put.php
4309 0x10D5 Unix path: /user/favorites/favorites/delete.php