Current location - Health Preservation Learning Network - Slimming men and women - Git principle deeply understands git add and git commit commands.
Git principle deeply understands git add and git commit commands.
(1) git repository (version repository): the git repository is a. git folder. This folder contains many files (see Figure 2), including an important folder object, which stores all file objects in the temporary storage area, including blob objects, tree objects, commit objects and so on. These objects are saved as files. There is also a header file, which holds the latest submitted pointer. Of course, many people here may not understand what the file object in objects and the pointer saved in HEAD really mean. It doesn't matter, it will be explained in detail below.

(2) Workspace: In a project directory, except. Git files are workspaces.

(3) Staging area: Staging area can be understood as the cache between file modification and final submission to git version library. In order to prevent unnecessary files from being submitted at one time and there is room for rollback, there is a staging area.

(4) Header: The header is in the file. Git folder. The content of the file is a 32-bit 16 hexadecimal number, just a pointer. This submission point is actually a submission object, which contains many attributes, including the directory structure index of the last submission point, the id of the last submission point, the submitter and the submission time.

(1) First of all, according to my thinking, let's create a git warehouse and understand the git add command through an example.

1. First, we create a warehouse through git init, and then we generate a. git folder, which is a git warehouse.

2. Create a A.java file.

Execute Gideon A.java.

Object file in. Git, I found an extra folder. Open it, there is a file with a string of symbols in it. Open this file, which contains a string of unrecognized characters.

What did git add do?

Actually, when executing the git add command, git will first calculate the sha- 1 corresponding to the file name A.java with the value of1fed2a34f13d2a34f13d, and this code is a 32-bit 16 hexadecimal number. Git will use the first two digits of this code as the folder name in the. Git/objects folder, with the last 30 bits of the code as the file name, in. Git will compress the contents of A.java's files to some extent.

to be continued .....

This article ends here. There may be some places in the article that are not clearly explained. Please specify the content of the discussion. If in doubt, please feel free to harass. Please reply as soon as you see it!