Git warehouse directory.git detailed

  table of Contents

1. Example environment

Second, the directory structure

2.1 The branches directory

2.2 COMMIT_EDITMSG file

2.3 config file

2.4 description file

2.5 HEAD file

2.6 hooks directory

2.7 index file

2.8 info directory

2.9 logs directory

2.10 objects directory

2.11 refs directory

3. References


When Git creates a warehouse, it creates a hidden directory named .git in the current warehouse directory to store warehouse configuration and data information. This article will introduce the basic directory of the Git repository with examples.

1. Example environment

The following examples are all carried out in the following environment:

System environment: CentOS Linux release 7.6.1810 (Core)

git version: git version 1.8.3.1

Remote warehouse: GitHub.

Second, the directory structure

Use the git init command to initialize the warehouse. The initial directory (.git) structure is as follows:

[root@192 testgit]# tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
└── refs
    ├── heads
    └── tags

9 directories, 13 files
[root@192 testgit]# 

 This initialized warehouse, when the branch dev-branch is created and pushed, the directory structure is as follows:

[root@192 testgit]# tree .git/
.git/
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       ├── heads
│       │   ├── dev-branch
│       │   └── master
│       └── remotes
│           └── origin
│               └── master
├── objects
│   ├── 2d
│   │   └── d2c71b69c837a7459f4bd9c9f7db6520731d06
│   ├── 5c
│   │   └── 7b8eda18a75e13d27c31e65a54b0abd7948510
│   ├── 77
│   │   └── cad3aecf7c2754231095598119979d62a1e1da
│   ├── info
│   └── pack
└── refs
    ├── heads
    │   ├── dev-branch
    │   └── master
    ├── remotes
    │   └── origin
    │       └── master
    └── tags

19 directories, 25 files
[root@192 testgit]# 

Next, each directory and file will be introduced in detail.

2.1 The branches directory

An infrequent storage shorthand method used to specify the URL of git fetch, git pull and git push, which is basically not used at present.

2.2 COMMIT_EDITMSG file

It is easier to understand by changing uppercase to lowercase, commit_editmsg: commit edit information, only record the latest commit edit information submitted, for example:

[root@192 testgit]# vim README
[root@192 testgit]# git add .
[root@192 testgit]# git commit -m "modify README file"
[master 2392c4d] modify README file
 1 file changed, 2 insertions(+), 1 deletion(-)
[root@192 testgit]# git push origin master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 315 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:New-World-2019/testgit.git
   3cbe67c..2392c4d  master -> master
[root@192 testgit]# cat .git/COMMIT_EDITMSG 
modify README file
[root@192 testgit]# 

In the above example, first modify the README file, then push it to the remote, write "modify README file" when committing, and then view the COMMIT_EDITMSG file and store the remarks when submitting. 

2.3 config file

Just look at the name and store the configuration information of the current warehouse. The git configuration file is divided into three layers, namely:

  1. / etc / gitconfig file: System general configuration of each user and their warehouse on;
  2. ~/.gitconfig or ~/.config/git/config file: the current user 's warehouse configuration;
  3. .git/config file (under the current warehouse): the configuration of the current user's current warehouse ;

The lowermost layer has the highest priority and will overwrite the upper layer configuration information. The above files can be modified through the git config parameter. The configurable information includes: user information, http information, warehouse information, etc.

[root@192 testgit]# cat ~/.gitconfig 
[user]
        name = New-World-2019
        email = [email protected]
[http]
        postBuffer = 1048576000
        lowSpeedLimit = 0
        lowSpeedTime = 999999
[root@192 testgit]# cat .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = [email protected]:New-World-2019/testgit.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "dev-branch"]
        remote = origin
        merge = refs/heads/dev-branch
[root@192 testgit]# git config --list
user.name=New-World-2019
[email protected]
http.postbuffer=1048576000
http.lowspeedlimit=0
http.lowspeedtime=999999
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
[email protected]:New-World-2019/testgit.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.dev-branch.remote=origin
branch.dev-branch.merge=refs/heads/dev-branch
[root@192 testgit]# 

In the above example, if the /etc/gitconfig file is not created in the system, it is not printed. It can be seen that the result of the git config --list command in the current warehouse is the sum of the files ~/.gitconfig and .git/config. If you need to know more configuration information, you can learn more through the git config command.

2.4 description file

Used to display project description information in GitWeb. The default content is as follows:

Unnamed repository; edit this file 'description' to name the repository.

2.5 HEAD file

Store the HEAD pointer to point to the current branch, that is, record the current active branch, for example:

[root@localhost testgit]# git status
# 位于分支 master
无文件要提交,干净的工作区
[root@localhost testgit]# cat .git/HEAD 
ref: refs/heads/master
[root@localhost testgit]# git checkout dev-branch
切换到分支 'dev-branch'
[root@localhost testgit]# cat .git/HEAD 
ref: refs/heads/dev-branch
[root@localhost testgit]# 

In the above example, the beginning is in the master branch. After switching to the dev-branch branch, the content of the file .git/HEAD becomes refs/heads/dev-branch.

2.6 hooks directory

There are many hook files (some scripts) stored in the directory. These files are custom scripts used by various Git commands and can be automatically executed at specific stages of Git, such as: commit, rebase, pull ) Before and after the operation. Some sample hooks are installed when you run git init, but they are all disabled by default. If you want to enable it, you need to delete the file .sample extension.

2.7 index file

Temporary storage area (stage), binary file.

2.8 info directory

Other information of the repository will be recorded in this directory.

info/exclude:  Ignore files in the specified mode, similar to .gitignore, but .gitignore is specific to each directory.

2.9 logs directory

Save all updated reference records. The directory structure is as follows:

[root@localhost logs]# tree
.
├── HEAD
└── refs
    ├── heads
    │   ├── dev-branch
    │   └── master
    └── remotes
        └── origin
            ├── dev-branch
            └── master

4 directories, 5 files
[root@localhost logs]# 

Among them, HEAD records all change records, including switching branches, and stores the change records of local and remote branches under logs/refs. 

2.10 objects directory

Git is a content-addressable file system. The core part of Git is a simple key-value data store. You can insert any type of content into the Git repository, and it will return a unique key through which the content can be retrieved again at any time.

The simple understanding is: the objects directory is a Git database (a key-value pair database can be imagined in the form of map[key] = value). The content is accessed according to the key, and the key is the value calculated by SHA1. There are three types of objects (at most) stored in this directory: data objects (blob objects), tree objects (tree objects), and commit objects (commit objects).

(1) info and pack directories

When the stored file is large, git will compress it and store it under info and pack;

(2) Directory of 2 character commands

First, these two letters are the first two characters of the calculated SHA1 value (40 characters in total), and the remaining 38 are the file names in the directory.

2.11 refs directory

(1) heads directory

The directory contains files named after each local branch name , and saves the latest submitted ID of the corresponding branch, which is a string calculated by the SHA1 algorithm.

(2) remotes directory

The directory contains files named after each remote branch name , saves the ID of the latest submission of the corresponding branch, and the principle of the heads directory.

(3) tags directory

Store the tags made during the development process, the files inside are commanded by the tag name, and the file content is the corresponding ID.

3. References

[1] What is Git's description file?

[2]  gitignore

[3] git branches

[4] gitrepository-layout

 

 

 

 

Guess you like

Origin blog.csdn.net/u011074149/article/details/109406589