Why is the git index binary?
Most of the files in my Git directory are plain text files (with the exception of compressed free objects and packfiles). So I can just quote and edit files like .git/HEAD
or .git/refs/heads/master
and check the repository if it's corrupted.
But it .git/index
is a binary file. Wouldn't a simple text file be helpful because it can be easily modified by hand?
In my opinion, this can be easily placed in a text file.
So why is it a binary file and not a plain text file?
source to share
The index provided in What does a git index contain, EXACTLY? ", contains metadata and below) , Jazimov , links:
- index entries : links to entries with metadata (time, mode, size, SHA1, ...)
- cached trees that refer to trees ("pre-computed hashes for trees that can be retrieved from the index"), which helps speed up the creation of the object tree from the index for a new commit.
Concatenating this data makes it a binary file, although the actual reason is pure speculation. There is no way to manually change it alone.
source to share
None of the reasons given in the answer adequately address the question of "Why is a Git file a binary file?" The accepted answer is simply not correct. The index does not "contain" any text files - it contains links to text files. Also, to say that the Git index contains "index entries" is really not useful, especially for another developer looking for Truth ... Finally, trees are not index-cached - tree references are cached.
The index is not binary because it is "indexed" (as the poster is enclosed in the comment above) - and it is not binary for "performance reasons" per se. Everything in an index can be expressed using a pure text file - even flags and bits expressed in a binary index file can be expressed as ASCII. It is binary because binary file formats containing bit flags can use disk space more efficiently. And, knowing Linus, he is probably binary to dissuade newbies from unauthorized access to text editors.
* New information * Version 4 of the index implements path compression, saving up to about 50% of the index size for large repositories. (Source: https://git-scm.com/docs/git-update-index ) This compression will succumb to the binary format index file.
source to share