github study notes (5) workspace and staging area

One difference between Git and other version control systems such as SVN is the concept of a staging area.

Let's look at the noun first.

Workspace (Working Directory)

It is the directory you can see on your computer. For example, my learngitfolder is a workspace:

working-dir

Repository

The workspace has a hidden directory .git, which is not a workspace, but a Git repository.

There are a lot of things in the Git repository, the most important of which is the staging area called stage (or index), the first branch that Git automatically created for us master, and mastera pointer to it called HEAD.

git-repo

We will talk about the concept of branch sum HEADlater.

As mentioned earlier, when we add files to the Git repository, it is performed in two steps:

The first step is to git addadd the file to it, which is actually to add the file modification to the temporary storage area;

The second step is to git commitcommit the changes, which actually commits all the contents of the staging area to the current branch.

Because when we created a Git repository, Git automatically created the only masterbranch for us, so now, git commitit's time to commit changes to the masterbranch.

You can simply understand that the file modifications that need to be submitted are all placed in the staging area, and then all the changes in the staging area are submitted at one time.

As the saying goes, practice brings true knowledge. Now, let's practice again, first readme.txtmake a modification, such as adding a line:

Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.

Then, create a new text file in the workspace LICENSE(write whatever content you want).

git statusCheck the status first with :

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   readme.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       LICENSE
no changes added to commit (use "git add" and/or "git commit -a")

Git tells us very clearly that it has readme.txtbeen modified and LICENSEhas never been added, so its state is Untracked.

Now, use the command twice git add, add the sum readme.txtand check again:LICENSEgit status

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   LICENSE
#       modified:   readme.txt
#

Now, the state of the staging area becomes like this:

git-stage

Therefore, the git addcommand actually puts all the changes to be submitted into the staging area (Stage), and then, execution git commitcan submit all the changes in the staging area to the branch at one time.

$ git commit -m "understand how stage works"
[master 27c9860] understand how stage works
 2 files changed, 675 insertions(+)
 create mode 100644 LICENSE

Once committed, the workspace is "clean" if you haven't made any changes to it:

$ git status
# On branch master
nothing to commit (working directory clean)

Now that the repository looks like this, there is nothing in the staging area:

git-stage-after-commit

summary

The temporary storage area is a very important concept of Git. If you understand the temporary storage area, you will understand what Git does with many operations.

Guess you like

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