Latest web development tutorials

Git work area, staging area and repository

basic concept

We first understand the working area under Git, temporary storage area and repository concept

  • Workspace: that you can see in the computer catalog.
  • Temporary Area: English called stage, or index. Generally stored in "git directory" index file (.git / index), so we sometimes called the temporary area index (index).
  • Repository: Workspace has a hidden directory .git, this is not the work area, but Git repository.

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

The figure on the left in the work area on the right side of the repository. In the repository labeled "index" of the area is a temporary area (stage, index), marked as "master" branch is represented by the master directory tree.

The figure we can see that at this time "HEAD" is actually pointing to a master branch "cursor." So place the command shown appearing HEAD can be used to replace the master.

FIG region objects identified as Git object library, actually located ".git / objects" directory, which contains a variety of objects and content creation.

When the work area to modify (or add) the file to perform "git add" command, the directory tree is updated staging area while the work area to modify (or add) the contents of the file is written to the object in a library the new object, and the object ID is recorded in a temporary area of ​​the file index.

When performing a commit (git commit), tree temporary area writing to the repository (object library), master branch will be updated accordingly. Scratch directory tree that is master zone when directed tree is submitted.

When performing "git reset HEAD" command, the directory tree staging area will be rewritten, it is replaced by the master branch point of the tree, but the work area is not affected.

When performing "git rm --cached <file>" command, delete files directly from the staging area, the work area is not to make a change.

When performing "git checkout." Or "git checkout - <file>" command, it will replace all paper work area with the staging area or the specified file. This operation is very dangerous, it will clear the workspace changes are not added to the staging area.

When performing "git checkout HEAD." Or "git checkout HEAD <file>" command, and will replace the temporary storage area and workspace file with the HEAD branch points to master all or part of the file. This command can also be very dangerous, because the changes will not only clear the workspace uncommitted changes will remove the temporary area uncommitted.