Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are Git workspaces, staging areas, and version libraries

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail the "what is the Git workspace, temporary storage area and version library" with detailed content, clear steps and proper handling of the details. I hope that this article "what is the Git workspace, temporary storage area and version library" can help you solve your doubts.

Basic concept

Let's first understand the concepts of Git workspaces, staging areas, and version libraries:

Workspace: the directory that you can see on your computer.

Temporary storage area: stage or index in English. It is generally stored in the index file (.git / index) in the .git directory, so we sometimes call the staging area an index.

Version library: the workspace has a hidden directory. Git, which is not a workspace, but a version library of Git.

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

In the figure, the left side is the workspace and the right side is the version library. The area marked "index" in the version library is the stage/index, and the area marked "master" is the directory tree represented by the master branch.

In the figure, we can see that at this point "HEAD" is actually a "cursor" pointing to the master branch. So where HEAD appears in the command shown in the diagram, you can replace it with 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.

When the git add command is executed on a file modified (or added) in the workspace, the directory tree of the staging area is updated, and the contents of the file modified (or added) in the workspace are written to a new object in the object library, and the ID of that object is recorded in the file index of the staging area.

When the commit operation (git commit) is performed, the directory tree of the staging area is written to the version library (object library), and the master branch will update accordingly. That is, the directory tree that master points to is the directory tree of the staging area at the time of submission.

When the git reset HEAD command is executed, the directory tree of the staging area is rewritten and replaced by the directory tree pointed to by the master branch, but the workspace is not affected.

When the git rm-- cached command is executed, the file is deleted directly from the staging area, and the workspace remains unchanged.

When executing git checkout. Or git checkout-- when using the command, the workspace file is replaced with all or the files specified in the staging area. This operation is dangerous and clears changes in the workspace that have not been added to the staging area.

When executing git checkout HEAD. Or the git checkout HEAD command replaces the staging area and the files in the workspace with all or part of the files in the master branch pointed to by HEAD. This command is also dangerous because it clears not only uncommitted changes in the workspace, but also uncommitted changes in the staging area.

After reading this, the article "what is the Git Workspace, temporary Storage area and version Library" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report