为什么git索引文件是二进制的? [英] Why is the git index file binary?

查看:195
本文介绍了为什么git索引文件是二进制的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Git目录中的大部分文件都是纯文本文件(压缩的松散对象和包文件除外)。所以我可以编辑和编辑像 .git / HEAD .git / refs / heads / master 这样的文件并检查如果存储库损坏的话。



但是 .git / index 是一个二进制文件。难道纯文本文件不会更有用,因为它可以很容易地用手修改吗?



Scott Chacon在他的中包含元数据和 Jazimov 参考文献 em>:


  • 索引条目:对元数据(时间,模式,大小,SHA1,...)条目的引用
  • 缓存树,对树的引用(可以从索引派生的树的预先计算的散列),这有助于加速从索引为新提交生成树对象。



这些数据的连接使其成为一个二进制文件,尽管实际原因是纯粹的推测。 能够通过手动修改它。


Most of the files in my Git directory are plain text files (except for the compressed loose objects and the packfiles). So I can just cat and edit files like .git/HEAD or .git/refs/heads/master and inspect the repository if it gets corrupted.

But the .git/index is a binary file. Wouldn't a plain text file be more useful because it can easily be modified by hand?

Scott Chacon shows in his presentation the following image (Slide 278):

In my opinion, this can easily be put to a plain text file.

So why is it a binary file rather than a plain text file?

解决方案

The index, as presented in "What does the git index contain EXACTLY?" contains metadata and, as noted below by Jazimov, references:

  • index entries: references to entries, with metadata (time, mode, size, SHA1, ...)
  • cached trees, that references to trees ("pre-computed hashes for trees that can be derived from the index"), which helps speed up tree object generation from index for a new commit.

The concatenation of those data makes it a binary file, although the actual reason is pure speculation. Not being able to modify it by hand could by one.

这篇关于为什么git索引文件是二进制的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆