Git init creates a git repository in the repository directory. Git init creates a git repository directory in the repository directory

Key contents in the. Git directory

ls -al total 40 drwxr-xr-x 12 xxx staff 384 Dec 13 19:25 . drwxr-xr-x 5 xxx staff 160 Dec 13 18:57 .. -rw-r--r-- 1 xxx staff 32 Dec 13 19:02 COMMIT_EDITMSG -rw-r--r-- 1 xxx staff 23 Dec 13 18:50 HEAD -rw-r--r-- 1 xxx staff  137 Dec 13 18:50 config -rw-r--r-- 1 xxx staff 73 Dec 13 18:50 description drwxr-xr-x 13 xxx staff 416 Dec 13 18:50 hooks -rw-r--r-- 1 xxx staff 217 Dec 13 19:02 index drwxr-xr-x 3 xxx staff 96 Dec 13 18:50 info drwxr-xr-x 4 xxx staff 128 Dec 13 18:57 logs drwxr-xr-x 10 xxx staff 320 Dec 13 19:02 objects drwxr-xr-x 4 xxx staff 128 Dec 13 18:50 refsCopy the code

HEAD

HEAD is a text file that records which branch Git is currently working on and changes when you switch branches

> cat HEAD
ref: refs/heads/master
Copy the code

config

Config is a text file that records configuration information about the current Git repository, including user-configured user names and mailboxes

> cat config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[user]
	name = your name
	email = [email protected]
Copy the code

refs

Refs is a directory that contains subdirectories for tags and heads. The subdirectories in the head directory correspond to local branches

> ls -al total 8 drwxr-xr-x 3 xxx staff 96 Dec 13 19:02 . drwxr-xr-x 4 xxx staff 128 Dec 13 18:50 .. -rw-r--r-- 1 XXX staff 41 Dec 13 19:02 Master #Copy the code

Git cat-file to check the type and content of the hash object

> cat master 5 dda4591f28955e4eaba649e46301e0d20869ffa > git cat - file - t dda4591f28 # 5 - t view object type commit > git cat - file - p 5 dda4591f28 # - p content tree view object ad5ba8ce8394ba313ff74503c2c8bdc07ca56331 84 ed89a79f290cbdab68bdc9468859a05d9fac77 parent author xxx <[email protected]> 1607857377 +0800 committer xxx xxx <[email protected]> 1607857377 +0800 add demo.html and modify readmeCopy the code

Therefore, it can be concluded that each text in the heads directory corresponds to a branch, and the content refers to the last commit of that branch.

objects

The objects directory contains the most important content in Git version control, that is, various objects

The # objects directory has a number of scattered folders (the first two hash objects are placed in the same directory), Ls-al Total 8 DRwxR-XR-x 3 XXX staff 96 Dec 13 19:02. Drwxr-xr-x 10 XXX staff 320 Dec 13 19:02 .. - r - r - r - 1 XXX staff 175 Dec 13 19:02 da4591f28955e4eaba649e46301e0d20869ffa > git cat - file - t # 5 dda4591f2895 directory name + name of the file = complete hash value commit > git cat - file - p 5 dda4591f2895 tree ad5ba8ce8394ba313ff74503c2c8bdc07ca56331 parent 84ed89a79f290cbdab68bdc9468859a05d9fac77 author xxx <[email protected]> 1607857377 +0800 committer xxx <[email protected]> 1607857377 +0800 add demo.html and modify readmeCopy the code

Git is a commit object. Git is a commit object.

Git Common Objects

Git has four common objects: Tag, Commit, Tree, and blob

The object operation

Before introducing the various objects, I introduce the next two commands to view the types and contents of objects

Git cat-file -t XXXX git cat-file -t XXXXCopy the code

commit

The commit object is a literal representation of each commit by the user, and is structured as follows

Contains the pointer to the tree object, its parent pointer, author, submitter, and description at the time of submission

tree

Tree represents a directory object in a project, structured as follows

Describes the structure of the corresponding directory, such as which directories and files are contained

blob

Blob stands for file object, and its structure is as follows

It is also important to note that the same file in Git corresponds to the same blob

This object describes the contents of the corresponding file

tag

Tag, which I won’t go into too much detail, is actually an alias for commit

Relationships between COMMIT, Tree, and BLOb objects

conclusion

This article mainly introduces the contents and meanings of various common directories and files under. Git directory. As well as the main git objects represent the meaning and its associated relationship, understand these, the basic git is how to achieve version control have a basic understanding

Series of articles (constantly updated)

Git Git

Git core concept (I) : Workspace and staging area

Probing into the Git directory

Git core concept (3) : separate header pointer