What is the file format of a git commit object? -


context: hoping able search through git commit messages , commits without having go through puzzlingly complex git grep command, decided see how git commit messages stored.

i took in .git folder, , looks me commits stored in

.git/objects  

the .git objects folder contains bunch of folders names a6 , 9b. these folders each contain file name looks commit sha 2f29598814b07fea915514cfc4d05129967bf7. when open 1 of files in text editor, gibberish.

  1. what file format gibberish / how git commit object stored?
  2. in git commit log, folder 9b contains 1 commit sha

    aed8a9f773efb2f498f19c31f8603b6cb2a4bc 

    why, , there case more 1 commit sha stored in file 9b?

  3. is there way convert gibberish plain text can mess commits in text editor?

before head down path further, might recommend read through the section in git manual internals. find knowing contents of chapter difference between liking git , hating it. understanding why git doing things way makes of sort of weird commands has things make more sense.

to answer question, gibberish seeing data object after has been compressed using zlib. if under heading "object storage" in link above can see details how works. short version of how files stored in git:

  1. create git specific header content.
  2. generate hash of concatenation of header + content.
  3. compress concatenation of header + content.
  4. store compressed data disk in folder name equal first 2 characters of data's hash , file name remaining 38 characters.

so answers second question, folder contain of compressed objects begin same 2 characters, regardless of contents.

if want see contents of blob, have decompress it. if want view contents of file, can done enough in programming languages. warn against trying modify data, however. modifying single byte in file change it's hash. of metadata in git (namely, directory structures , commits) stored using references hashes, modifying single file means you must update objects downstream file reference file's hash. have update objects reference hashes. , on, , on, , on... trying achieve becomes very, complicated quickly. you'll save self lot of time , heartache learning git's built in commmands.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -