Git workspaces, registers, and version libraries
Basic concepts
Let's understand the Git workspace, registers, and version library concepts first.
Workspace: is the directory you can see on your computer.
Registers: English is called stage, or index. Typically stored in the index file (. git/index) under Git directory, so we sometimes call registers index.
Version Gallery: The workspace has a hidden directory. Git, this is not a workspace, but a repository of git.
The following diagram shows the relationship between the registers in the workspace, the version library, and the version library:
The left side of the diagram is the workspace and the right side is the version library. The area marked "index" in the repository is registers (stage, index), which is labeled "Master" as the directory tree represented by the master branch.
In the diagram we can see that the head is actually a "cursor" pointing to the master branch. So the place where the head appears in the command in the diagram can be replaced with master.
The objects identified in the figure is a Git object library, which is actually located under the ". Git/objects" directory, which contains the various objects and content created.
When you perform a "git add" command on a file that is modified (or added) to the workspace, the registers directory tree is updated, and the workspace modification (or new) file contents are written to a new object in the object library, and the object's ID is recorded in the registers file index.
When a commit operation (Git commit) is performed, the registers tree is written to the version library (object library), and the master branch updates accordingly. The directory tree that master points to is the registers directory tree at the time of submission.
When the git reset Head command is executed, the registers directory tree is overridden and replaced by the directory tree that the master branch points to, but the workspace is unaffected.
When the git RM--cached <file> command is executed, the files are deleted directly from registers, and the workspace does not make changes.
When you perform the "Git checkout." or "Git checkout-<file>" commands, you replace the workspace files with registers all or specified files. This operation is dangerous and clears changes that are not added to the registers in the workspace.
When the "Git Checkout head" or "Git Checkout head <file>" command is executed, the registers and files in the workspace are replaced with all or part of the files in the Master branch pointed to by the head. This command is also extremely risky, as it will not only clear uncommitted changes in the workspace, but also clear uncommitted changes in the registers.