1. Hash
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:
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.
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.
2.3 Git file management mechanism details
-
Git's "submit object"
-
The chain formed by the submitted object and its parent object
3. Branch management mechanism
3.1 Branch creation
3.2 Switching of branches