1

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

Ondrej Slinták
  • 31,386
  • 20
  • 94
  • 126
Ashish
  • 14,295
  • 21
  • 82
  • 127
  • 1
    Errr..., compressed blob stored in .git/objects. Don't understand what the question is. – Alexey Ten Feb 09 '15 at 17:52
  • @AlexeyTen I think .git/objects only store the SHA1 I do not see any object in that directory – Ashish Feb 09 '15 at 17:55
  • @mu無 I can not see anything else but the SHA1 in .git/objects – Ashish Feb 09 '15 at 17:55
  • @Ashish yep, that's files named as SHA1 of their content. – Alexey Ten Feb 09 '15 at 17:57
  • 1
    @Ashish Are you sure you are looking at the right directory? In one of my repos, I can clearly see files of the kind `.git/objects/fd/0b949f2d8db5b2a518e8adb10a39c81a1fc399` where `fd0b949f2d8db5b2a518e8adb10a39c81a1fc399` would be the SHA, and the insides of the file is some binary garbled text. – Anshul Goyal Feb 09 '15 at 17:58
  • @AlexeyTen thanks, so I wanted to know where that blob store – Ashish Feb 09 '15 at 17:58
  • @Ashish may be you need to read this http://git-scm.com/book/en/v2/Git-Internals-Git-Objects – Alexey Ten Feb 09 '15 at 18:04

1 Answers1

7

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
Community
  • 1
  • 1
bames53
  • 86,085
  • 15
  • 179
  • 244