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 studygit
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
.
HEAD
the 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
git add
add the file, in effect, to add the file changes to the staging area (stage);
- 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:
Test git modify Secondstudy gitthree add
Then, add a text file to the workspace test.txt
(the content is written casually).
Check the git status
status first:
$ git Statuson branch masterchanges not staged for commit: (use "git add <file> ..." to update the What would Be committed) (use "Git checkout--<file> ..." to discard changes in working directory) modified:
readme.txtuntracked files: (use "git add <file> ..." to include in what'll be
committed) Test.txtn o 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
test.txt
both add and post.
$ git add readme.txt test.txt
Take a git status
look again:
$ git Statuson Branch masterchanges to being committed: (use "git reset HEAD <file> ..." to unstage) modifie D: readme.txt new file: test.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.
$ git commit-m "three modify"[Master 83a4b1e] Three modify 2 files changed, 3 insertions (+), 1 deletion (-) Crea Te mode 100644 test.txt
Once submitted, if you do not make any changes to the workspace, then the workspace is "clean":
$ git Statuson branch masternothing to commits, working directory clean
Now that the repository has changed, staging area has no content:
GIT Workspaces and Staging area