Workspaces and Staging Area
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 github folder is a workspace:
Version Library (Repository)
The workspace has a hidden directory .git , which does not count as 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 add the file git add , in effect, to add the file to the staging area;
The second step is to commit the git commit changes, in effect, to commit 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:
[Email protected]:~/github$ git Statuson branch masterchanges not staged forCommit: ( use"git add <file>, ... ."To update what'll be committed) ( use"git checkout--<file>, ... ."To discard changesinchworking directory) modified:readme.txtUntracked files: ( use"git add <file>, ... ."To includeinchWhat'll be committed) LICENSE.txt LICENSE.txt~Readme.txt~no 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, with two commands git add , readme.txt LICENSE Add and both after:
[Email protected]:~/github$ git add readme.txt
[Email protected]:~/github$ git add LICENSE.txt
Take a git status look again:
[Email protected]:~/github$ git statuson branch masterchanges to be committed: "git reset HEAD <file>, ..... " To unstage) file : LICENSE.txt Modified: readme.txtuntracked files: "git add <file> " in what'll be committed) LICENSE.txt~ readme.txt~
Now, the state of staging area becomes this:
So, the git add command actually puts all the changes you want to commit to staging area (Stage), and then executes git commit it to commit all the staging area changes to the branch at once.
" Understand how stage works " 231 deletion (-100644 LICENSE.txt
Once submitted, if you do not make any changes to the workspace, then the workspace is "clean":
[Email protected]:~/github$ git statuson branch masteruntracked files: "git add <file> ... " inch What'll be committed) LICENSE.txt~ readme.txt~"git add" to track)
Now that the repository has changed, staging area has no content:
Reference articles
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
Git Learning notes 2