Git (5): The basic principles of Git

1. Hash

Insert picture description here
Hash is a series of encryption algorithms. Although different hash algorithms have different encryption strengths, they have the following common points:

  • Regardless of the amount of input data, if the same hash algorithm is input, the length of the encryption result is fixed;
  • The hash algorithm is determined, the input data is determined, and the output data can be guaranteed to be unchanged;
  • The hash algorithm determines that the input data has changed, and the output data must have changed, and it usually changes greatly;
  • The hash algorithm is irreversible;

The underlying Git uses the SHA-1 algorithm.

Hash algorithms can be used to verify files. The principle is shown in the figure below:
Insert picture description here
Git uses this mechanism to fundamentally ensure data integrity.

2. Git save version mechanism

2.1 File management mechanism of centralized version control tools

Store information in the form of a file change list. Such systems treat the information they save as a set of basic files and the cumulative differences of each file over time.
Insert picture description here

2.2 Git's file management mechanism

Git treats data as a set of snapshots of a small file system. Every time an update is submitted, Git will make a snapshot of all current files and save the index of this snapshot. For efficiency, if the file is not modified, Git will not re-store the file, but will keep a link to the previously stored file. So the way Git works can be called a snapshot stream.
Insert picture description here

2.3 Git file management mechanism details

  • Git's "submit object"
    Insert picture description here

  • The chain formed by the submitted object and its parent object
    Insert picture description here

3. Branch management mechanism

3.1 Branch creation

Insert picture description here

3.2 Switching of branches

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/houwanle/article/details/112592065