Git workspaces, staging areas, and repositories

First, let's understand the concepts of Git workspace, staging area and repository

  • Workspace: It is the directory that can be seen on the computer.
  • Temporary storage area: English is called stage, or index. Generally stored in the index file (.git/index) under the ".git directory", so the temporary storage area is sometimes called the index (index).
  • Repository: The workspace has a hidden directory .git, which is not a workspace, but a Git repository.

The directory structure of the staging area and the version area is as follows:


 

The following diagram shows the relationship between the workspace, the staging area in the repository, and the repository:



The left side of the figure is the workspace, and the right side is the repository. The area marked "index" in the repository is the staging area (stage, index), and the area marked "master" is the directory tree represented by the master branch.

In the figure, we can see that "HEAD" is actually a "cursor" pointing to the master branch. Therefore, the place where HEAD appears in the command shown in the figure can be replaced by master.

The area identified by objects in the figure is the object library of Git, which is actually located in the ".git/objects" directory, which contains various objects and contents created.

1. When the " git add " command is executed on the modified (or newly added) files in the workspace, the directory tree of the temporary storage area is updated, and the contents of the modified (or newly added) files in the workspace are written into the object library in a new object, and the ID of the object is recorded in the file index of the staging area. index syncs the workspace .

2. When the commit operation ( git commit ) is performed, the directory tree of the temporary storage area is written to the repository (object repository), and the master branch will be updated accordingly. That is, the directory tree pointed to by master is the directory tree of the temporary storage area at the time of submission. master sync index .

3. When the " git reset HEAD " command is executed, the directory tree in the staging area will be rewritten and replaced by the directory tree pointed to by the master branch, but the workspace will not be affected. index sync master .

4. When the " git rm --cached <file> " command is executed, the file will be deleted directly from the temporary storage area , and the workspace will not be changed.

5. When the "git checkout . " or " git checkout -- <file> " command is executed, the files in the workspace will be replaced with all or the specified files in the staging area. This operation is dangerous and will clear changes from the workspace that were not added to the staging area. Workspace sync index .

6. When the " git checkout HEAD . " or " git checkout HEAD <file> " command is executed, all or part of the files in the master branch pointed to by HEAD will be used to replace the files in the staging area and the work area. This command is also extremely dangerous, as it will clear not only uncommitted changes in the workspace, but also uncommitted changes in the staging area. Workspace and index sync master .

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326570534&siteId=291194637