Understand the three states and working modes of Git files

Posted Jun 4, 20201 min read

Understand the three states and working modes of Git files

When using Git to manipulate files, the status of the file has the following three types:

Status Description
Committed Committed means that the data has been safely stored in the local database.
Modified Modified means that the file has been modified, but it has not been saved in the database.
Staged staged means that the current version of a modified file is marked to be included in the next commit snapshot.

For the three states of the Git file, here you need to understand the three working areas of the Git project:the work area, the temporary area, and the Git repository.

Category Description
Workspace Simple understanding is the directory that can be seen on the computer, such as the local project directory created by yourself
Temporary area There are many things in the Git repository, the most important of which is the temporary area called stage(or index), and the first branch master created automatically by Git, and the one that points to the master The pointer is called HEAD.
Git Repository The workspace has a hidden directory .git, which is not a workspace, but a Git repository.

The basic Git workflow is described as follows:

  • Modify some files in the work area.
  • Take a snapshot of the modified file and add it to the temporary storage area.
  • Submit the update and permanently dump the snapshot of the file saved in the temporary storage area to the Git repository.

The flow chart is as follows: