preface
Learn Git principle, from the storage location, three areas, four objects, storage process to analyze Git principle why to analyze it, so that you can better understand the whole Git naming operation dry “”? To correspond to a real case
Storage location
Introduction to the
Let’s see what’s in the Git file
Note: Enter ls -a in terminal to show directory hidden files (.git folder is hidden by default)
A brief introduction to Git common folder functions
- {commit-editmsg} stores the last committed message
- {description} is used for GitWeb programs
- {config} configures Settings specific to the repository
- {hooks} Places client-side or server-side hook scripts
- {HEAD} specifies which branch is currently in
- {objects} Git object storage directory
- {logs} is used to record operation information
- Refs} Git reference storage directory
- {branches} Lists of references to places of branches
- {index} saves temporary area information
details
The “objects” folder is the “objects” folder. The “objects” folder is the “objects” folder
Git uses sha-1 to generate a 40-bit hash of the contents of the file, taking the first two bits as the directory name. The 38-bit value is used as the file name (the file content is converted to binary content) and the location of our project’s data is stored in the Objects Treasure folder
The pack folder packs the modified files into a binary file called xxx.pack to save space and improve efficiency.
Three regions
Introduction to the
Git has three important areas: the working area, staging area (index area), and local repository
details
- Work area: This is where the files, code development and work on the project are done.
- Temporary storage area: proceedaddThe area added to after the operation can be thought of as a staging area where the code will be stored next timecommitIs committed to the local database.
- Local warehouse:commitGit Object records each Blob submittedpushTo remote warehouse
conclusion
The process is as follows: Workspace -> (Add) Staging area -> (COMMIT) Local repository -> (Push) Remote repository
Four types of objects
Introduction to the
There are four types of objects in Git: blob, Tree, Commit, and Tag.
details
- Blob: To store the contents of file data, usually a binary file.
- Tree: A directory with subdirectories that manage “trees” or “blobs”The final node is the BLOB.
- Commit: Points to a commit, that is, to only one tree object. There are also timestamps, authors of the most recent commits, and pointer methods referring to previous commits.
- Tag: To mark a commit method.
Storage process
Create/modify a file
Files are created and modified in the workspace without affecting the staging area and the local repository
The add operation
Running git add a.file will happen:
- A. file was added to the index area.
- The SHA-1 algorithm is used to generate a 40-bit hash value based on the file content.
- Create a blob in the Objects directory of the local repository (the first two bits of the hash value create the folder and the remaining 38 bits for the file name).
- The updated index points A.file to the newly created bloB.
The commit operation
Running git commit -m “will happen:
- Produces a tree object based on the current index.
- Create a new commit object that points to the tree and points the last commit pointer to the previous commit to form a log chain
- Move the pointer to the current branch to the new COMMIT node.
- Wait for push to the corresponding remote repository
Afterword.
Simple Git reference learning principle is as follows: www.jianshu.com/p/ddef78e9f… Juejin. Cn/post / 684490…
The cheeky Lord Lin’s Cabin series:
- Master Lin’s Hut – Git principles
- Lord Lin’s Hut – Computer Network
- Lord Lin’s Cabin – Web security/operating system/performance optimization
- Lord Lam’s Cabin – JS Basics (2)
- Lord Lam’s Cabin – JS Basics (I)