Home >Development Tools >git >The underlying processing flow of git
The popularity of code hosting platforms such as GitHub and GitLab has made Git a much-discussed version control tool, and more and more people have understood how Git works. However, understanding the appearance of Git is only to use Git. To truly understand Git, you also need to understand the underlying processing flow of Git.
Git is a distributed version control system, corresponding to a centralized version control system (such as SVN). Because of the distributed nature of Git, each Git repositories are complete repositories.
The working directory of Git contains two parts: Git warehouse object and working tree. The status of Git warehouse object and working tree can be analogized to the relationship between aliases, hard links and soft links respectively.
Git’s underlying file storage technology is mainly divided into two aspects:
Git saves all code changes as individual objects, among which the key objects are blob, tree and commit. Among them, blob is a snapshot of code content, tree is a snapshot of a set of files and directories, and commit is a snapshot of code changes.
Careful readers will find that these objects are somewhat similar to the inode mechanism in Linux systems. An inode file node can represent a file or directory, and an inode file node contains information such as the disk block number. In Git, blob is the snapshot object of the file content in the inode file node, tree is the snapshot object of the inode directory, and commit is the version snapshot composed of multiple inode file nodes.
In Git, objects are usually represented as SHA1 hashes. The SHA1 hash value is a hexadecimal string of 40 characters. Git uses SHA1 hashes to assign a unique identifier to each version, each file and directory, and each commit.
The bottom layer of Git uses a technology that adds a part of metadata to the file to handle code changes. Metadata is often some intermediate state, such as change information between two commits. This information can be compressed into small files and decompressed when needed.
The default file format used by Git is packfile format. Packfile is a highly compressed Git object storage format that can archive multiple objects into a single file for transfer when Git performs cross-network operations.
In the previous content, we have a detailed understanding of Git objects and underlying file storage technology. Next, we will enter the underlying core processing process of Git.
Here we first introduce Git A brief introduction to the various basic file commands:
Git's submission process still consists of three fields: Blob, Tree, and Commit.
In the above steps, there are some things that need to be paid attention to. For example, when performing Blob conversion, you need to add the -g parameter.
In Git, branches are independent pointers pointing to the last submitted object. There are two types of branches: local branches and remote branches.
After the local branch is created, adding a new submission will automatically move HEAD to point to the latest submission. During this period, the checkout command is used to switch between different branches. Remote branches refer to a way of collaborating code between different local libraries.
This article elaborates on the underlying processing process of Git from two aspects: Git's underlying file storage method and Git's underlying core processing process. Through the explanation of Git objects and underlying file storage technology, we understand the underlying architecture of Git. This article also introduces the underlying core processing process of Git, including Git's initialization process, Git's basic file commands, Git's submission process, and Git's branch process. Through an in-depth understanding of the underlying processing flow of Git, we can better understand the operating mechanism of Git and use Git for version control more efficiently.
The above is the detailed content of The underlying processing flow of git. For more information, please follow other related articles on the PHP Chinese website!