Home > php教程 > PHP开发 > Detailed explanation of workspace, staging area and repository of Git tutorial

Detailed explanation of workspace, staging area and repository of Git tutorial

黄舟
Release: 2016-12-16 14:48:17
Original
1182 people have browsed it

Git workspace, staging area and repository

Basic concepts

Let’s first understand the concepts of Git workspace, staging area and repository

Workspace: It’s what you can see on your computer Table of contents.
Temporary storage area: called stage in English, or index. It is generally stored in the index file (.git/index) under the "git directory", so we sometimes call the temporary storage area the index (index).
Repository: There is a hidden directory .git in the workspace. This is not the workspace, but the Git repository.

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

Detailed explanation of workspace, staging area and repository of Git tutorial

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 master The directory tree represented by the branch.

We can see in the picture that "HEAD" is actually a "cursor" pointing to the master branch. So where HEAD appears in the command shown in the picture, you can use master to replace.

The area identified by objects in the picture is the Git object library, which is actually located in ".git/objects" directory, which contains various objects and content created.
When executing "git add" on files modified (or added) in the workspace When executing the command, the directory tree in the temporary storage area is updated, and at the same time, the modified (or newly added) file contents in the workspace are written to a new object in the object library, and the ID of the object is recorded in the temporary storage area. File indexing.

When a commit operation (git commit) is performed, the directory tree in the staging area is written to the version library (object library), and the master branch will be updated accordingly. i.e. master The directory tree pointed to is the directory tree of the temporary storage area at the time of submission.

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.

When the "git rm --cached " command is executed, the file will be deleted directly from the staging area, and the workspace will not be changed.

When executing "git checkout ." or "git checkout -- " command, the files in the workspace will be replaced with all or specified files in the staging area. This operation is dangerous and will clear changes in the workspace that have not been added to the staging area.

When executing the "git checkout HEAD ." or "git checkout HEAD " command, the point pointed to by HEAD will be used master All or part of the files in the branch replace the files in the staging area and workspace. This command is also extremely dangerous, because it will not only clear the uncommitted changes in the workspace, but also clear the uncommitted changes in the staging area.

The above is the detailed explanation of the workspace, temporary storage area and repository of the Git tutorial. For more related articles, please pay attention to the PHP Chinese website (m.sbmmt.com)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template