Workspaces and Staging Area

Source: Internet
Author: User

One of the differences between Git and other version control systems like SVN is the concept of staging area.

First look at the noun explanation.

Workspaces (working Directory)

Is the directory you can see on your computer, like my learngit folder is a workspace:

version Library (Repository)

Workspace has a hidden directory .git , this is not a workspace, but a git repository.

Git's repository contains a lot of things, the most important of which is called the Stage (or index) of the staging area , as well as git for us to automatically create the first branch master , and pointing master to a pointer called HEAD .

HEADthe concept of branching and we speak later.

When we added the file to the Git repository, it was done in two steps:

The first step is to use git add Add the file, in fact, the file is modified to add to the staging area;

The second step is to use git commit committing the change is, in effect, committing all the contents of the staging area to the current branch.

Since we created the Git repository, Git automatically created the only branch for US master , so now it's time to git commit commit the changes to the master branch.

You can simply understand that the file changes that need to be submitted are all put to staging area, and then all changes to staging area are submitted at once.

As the saying goes, practice is the truth. Now, let's practice again and readme.txt make a change, such as adding a line of content:

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

Then, add a text file to the workspace LICENSE (the content is written casually).

Check the git status status first:

$ git status#  On branch master# Changes not staged for commit:#    ( use  "Git add <file> ..."  to update what will be committed) #     (use  "GIT&NBSP;CHECKOUT&NBSP;--&NBSP;<FILE> ..."  to discard changes  in working directory) ##       modified:    readme.txt## untracked files:#    (use  "Git add <file> ..."   to include in what will be committed) ##        LICENSEno changes added to commit  (use  "Git add"  and/or  " Git commit -a ")  

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

Now, using the two commands git add , readme.txt Add and LICENSE then look at the following git 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 staging area becomes this:

So, git add The command actually puts all the changes you want to commit to staging area (Stage), and then executes git commit to commit all of the staging area changes to the branch at once.

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

Once submitted, if you do not make any changes to the workspace, then the workspace is "clean":

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

Now that the repository has changed, staging area has no content:

Summary

Staging area is a very important concept of git, figuring out staging area, figuring out what a lot of git's operations are doing.

I don't know what's going on staging area. Children's shoes, please scroll up the page and look again.

Workspaces and Staging Area

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.