Article Directory
Every Git repository will have a ".git" directory, which is the core of Git repository, version information and stores configuration information for the warehouse. Today, let us look at what the secret has ".git" directory.
Just open a warehouse ".git" directory, you will find that there will be several such files and folders:
A, HEAD file
HEAD file stores the current working branch. Look at the contents of the file:
This represents the beginning of the ref is a reference, but where does this reference point, point refs / head / master this path.
And then look at the branch:
Git HEAD file is based on this work to determine the current branch. If you switch the current branch, the contents of this file will also change.
Two, refs folder
heads
From the previous section we know, HEAD file stores the current working branch, which is actually a path: refs / heads / master. So refs folder is doing, and we went inside to check it out. Came .git / refs / heads directory, found that there are two files, master and temp, which is two branches of our current warehouse. Respectively, look at the contents of the master and temp files:
Files stored in a string of hash. Each string hash value is actually pointing to an object, git cat-file -t 哈希值
you can view the type of object that points to the hash value of the order.
The results show, that the hash value string of a commit point is the object type.
Note that I'm looking at the hash value points to the object type, and did not use the full hash value, the original complete hash value is "783bbca61fea9dcd8e1b0ba3e7bb8cc8d5bb2a61" I only used the first few characters of the string of hash values "783bbca" actually can show normal results, because if this had been the first few characters are unique, then Git can find the corresponding object based on these characters without the need to use the full hash.
And when we look at the branch,
will find this point to commit the current master is also a hash value of 783bbca. temp is the same. It can be seen, refs / heads of this path is stored commit object currently pointed each branch.
tags
refs followed by a folder called tags.
tag is equivalent to a milestone project for the more important commit, such as project released version 1.0 of the time, this will commit marked with a tag, which is tag. tags below this folder will be stored in the warehouse all the tag, each tag files are stored with a hash value, point is marked with the label commit object.
Three, config file
config file stores the configuration information in the local warehouse. Look at the contents of the file:
there is some configuration information is stored, if we modify the contents of this document, for example, I put the user name changed supermouse666, and then go to check the configuration, you will find the user name has changed.
Vice versa, if you use Git commands modify the local repository user name, then the file content changes also occur. For example, I put mail into [email protected]
Four, objects folder
The figure is objects folder some children file stored inside the folder, wherein ① part are objects stored, and ② portion inside the pack folder special, its role is, when the warehouse more loose object file when , Git will automatically do the sort, these files are packaged loose objects into the pack folder.
Just open a folder, which kept the object file.
Folder name + file name will form a hash value, the hash value to an object, look at the type of the object:
It is an object of type blob, that a file object. You can use git cat-file -p 哈希值
this command to view the contents of the object.
We can see the contents of the code file but in fact what we submitted.