Reputation: 14707
I understand that git compress the file and then calculate the SHA1 and store that in .git/objects/
and we can see the content using git cat-file -p 'sha1'
but I am interested to know where does git store the compressed blob objects.
as mentioned in the following post
http://gitready.com/beginner/2009/02/17/how-git-stores-your-data.html
Update
I can only see SHA1
in .git/objects
which I think are reference to the actual blob rather than blob
Upvotes: 2
Views: 1332
Reputation: 88155
I understand that git compress the file and then calculate the SHA1
Git computes the SHA1 hash of the uncompressed file, Then it compresses the data and stores it in .git/objects, using the SHA1 as the filename.
Example:
1. create a test repository
$ mkdir tmp
$ cd tmp
$ git init .
Initialized empty Git repository in /tmp/.git/
2. add a test file
$ echo 'hello, world' > hello.txt
$ git add hello.txt
$ git commit -m "Initial commit"
[master (root-commit) 951d5cc] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
3. display the test file's content in the .git/objects directory
$ git hash-object hello.txt
4b5fa63702dd96796042e92787f464e28f09f17d
$ cat .git/objects/4b/5fa63702dd96796042e92787f464e28f09f17d
xKOR04fQ(I??
$ python -c "import zlib,sys;print repr(zlib.decompress(sys.stdin.read()))" < .git/objects/4b/5fa63702dd96796042e92787f464e28f09f17d
'blob 13\x00hello, world\n'
The script in the last line is from this answer.
As you can see, the file content in .git/objects is not viewable directly, cat
displays it only as xKOR04fQ(I??
. The file is also not stored in a standard container for compressed data, but using zlib you can decrompress the raw data. The stored file also contains git metadata about the content: the type of git object and the length of the content. But the data is clearly stored right there in .git/objects:
blob 13\x00hello, world\n
Upvotes: 8