Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does git store file names?

Tags:

git

I understand git uses content to address file contents, and the content hash is used as object file name. Then where does git store original file names? For example, when git checkout a commit, how does it get the file names back from objects? And how does git handles renaming?

Thanks

like image 489
A.Stone Avatar asked Jan 17 '17 14:01

A.Stone


People also ask

What is stored in the git directory of a git repository?

What is stored in the .git directory of a git repository is pretty well described in the documentation: * The ‘objects/’ subdirectory, which contains the blobs that represent file data, tree objects, commit objects, and signed tag objects. Together, these make up the data model underlying git. In case it helps others...

Where are files stored in git after commit?

Until the files are committed they go through the regular file operations of the local computer. So until saved the files are stored in memory, and once saved they are stored on the local disk. During the commit and push operations the regular git structure is followed. git status Does Git track empty folders?

What is the object folder in Git?

Inside the .git folder, we can see there is an object folder also known as object database this is where our commits are basically stored in a form of an object. Since the object database can only store objects inside it hence now we can say that the commits which we store in it are also an object.

Where is the Git-credentials file stored?

The .git-credentials file is stored in plaintext. Each credential is stored on its own line as a URL like: Each credential is stored on its own line as a URL like: https://user:[email protected]


1 Answers

Git stores a commit as an object, and you can look at those objects. For instance, take a commit ID, you can look at it in a raw file form.

$ git cat-file -p 3d911c37dc7cc6d50af9cbc66aa36084158308f5
tree 487660899e53bef8b15d3e1692172f689ed965c5
parent aa3b68973e845b7a900ab164603f154c8a1ba1c5
author Dan Lowe <[email protected]> 1483760015 -0500
committer Dan Lowe <[email protected]> 1483760015 -0500

Update line number settings in vim for 7.4+

As you can see, part of the commit is a tree object. This is where the file paths are stored. You can also examine that object using the same mechanism as above, and you'll see the path names. Here is the tree object noted in the above commit:

$ git cat-file -p 487660899e53bef8b15d3e1692172f689ed965c5^{tree}
100644 blob fc99cb33777f31c151278740abae2a9e6a2f7356    .gitignore
100644 blob b727328afdaa7ade85a89c1c1bde3c1bad0524a9    README.md
040000 tree affb2dde9693434395cc5c427f53c50b5f25f95d    bash
100644 blob 95c2c67c1a3cf22a8ae9bb6c801a51e0fb0723f2    bash_profile
100644 blob 5083122a9ce0d6b8cc5219cfe25f3f14087be00b    bashrc
100644 blob 2edff3b0b1c912cd020619dcb8e70284328d5457    colordiffrc
100644 blob 58e72f6937ba6c3e9119328eeacccd0e141dbc53    cvsrc
100644 blob 9e7a88c4db0d022d174a7dcb9e712999d2c256f1    emacs
100644 blob fb85e6f14ec59c76a74e9cd7119f060808ab64f6    gitconfig
100644 blob 6b5a544e8cacb49a419f062aa4130edbec057af3    gitignore
100644 blob 2a1154da1b962dcdd9fd8e56c691315e3145b0ef    hgrc
100644 blob ef8a9c0034a129853b3e128efac02f86f0ecf0dc    inputrc
100755 blob 96b2cac25e910ff031921003334eb0a35ea64e3f    install.pl
100644 blob 83bce8d003a7620f6c35f489651da254c6376512    ircrc
040000 tree dafeb513b528067139128480b1223a41d6fa3f92    lib
100644 blob 8bd4ed3e6de8e10543f202816d8414f4ed4ebcc2    perldb
100644 blob 3c4f18565031942b8c85428276c81bb7238a1983    perltidyrc
100644 blob 5fe87e63c55725a70891510d9940eccd8bb5f734    pgclirc
100644 blob 7c400b451eefcbff3057146d430be92b2f86e09c    pryrc
100644 blob 753e436e761394641b6eb7ac08a26c61ae56e04c    psqlrc
100644 blob b5eb20d055a89f0b680c1a60fbe9325d018ef1d6    screenrc
040000 tree eaa4bfe31780f6ae866181d29ddac3f350d4130f    scripts
100644 blob 1a57ec4dd3ecb92e0139af37563e1b3402a49e62    tcshrc
040000 tree cc106ffdee9efcfb22c1af9660a342853a47bee5    terminfo
100644 blob cf64f721be160dcc0f09852ee928d27836e13f26    tmux.conf
040000 tree 6ba373cc4a269d51b07b9b4c22816c8dcc140986    vim
100644 blob 109608f97d29d495ced16f4b507cf05981241b8d    vimrc
100644 blob bb8b48639b198fe4af3648886e40d8a8f19611f7    zlogin
100644 blob f291f18aae6be481b5ac58ec9833e8e67f6e63b5    zlogout
100644 blob c976c7f3ff67b911de3eb49672f40b4652f5118e    zshenv
100644 blob 9b2f38ad7c0941e928d6d33b6abb58addb29f179    zshrc

Here most objects are blobs (files). But you can see there are other trees here too. You can look into those and see what else changed. For instance above there is a tree object for "bash".

$ git cat-file -p affb2dde9693434395cc5c427f53c50b5f25f95d
100644 blob dfc93b18e48ce6a75688b612c6f022f94b764029    alias.sh
100644 blob 83841c91abe242a7a400bd8cdc90eb2f8e827feb    completion.sh
100644 blob d141fafeef4f89d015ccd2616f9b653167e957e8    config.sh
100644 blob f61e217197de7a8d7e069e06067184849bc4ebb2    environment.sh
100644 blob 9c5c706dc2bb80a672b60c3c769e78883533401d    function.sh
100644 blob c6dc2b8963a6c4e4a53df41f0ad7e354e5da8fd7    library.sh
100644 blob c29db806365b731e60c2ad161a7d3a89d32def34    mac.sh
100644 blob 94f5b6f2a8e792c0cd3e502085418c91bd02aefe    non-root.sh
100644 blob d7c41e0a5fb7f4456a70dac069ea5cb568de4faf    project-mgmt.sh

So these would refer to bash/alias.sh, bash/completion.sh, and so on.

You can read more about trees in the the git documentation.

like image 193
Dan Lowe Avatar answered Oct 17 '22 01:10

Dan Lowe