什么是
工作区
:就是我们平常可以看到的目录
版本库(Repository):在创建git仓库之后,此时文件夹下会自动生成一个.git
目录,这个就是版本库,但不是工作区
暂存区:版本库中会生成很多东西,其中最重要的就是称为stage
(或者叫index
)的暂存区
,还有Git为我们自动创建的第一个分支master
,以及指向master的一个指针叫HEAD
例如:我们对已有的文件进行更改
Simple@Simple MINGW64 ~/Desktop/gitdir (master)
$ 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: test.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
learn.txt
no changes added to commit (use "git add" and/or "git commit -a")
此时,Git非常清楚地告诉我们,test.txt
被修改了,而learn.txt
还从来没有被添加过,所以它的状态是Untracked
这时,我们可以使用git add
将两个文件都添加,可以再查看一下状态
Simple@Simple MINGW64 ~/Desktop/gitdir (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: learn.txt
modified: test.txt
这时候,命令git add
把修改的内容都放到了暂存区(Stage),此时再执行git commit
就可以将暂存区的内容一次性提交到分支
Simple@Simple MINGW64 ~/Desktop/gitdir (master)
$ git commit -m "test"
[master 686c787] test
2 files changed, 2 insertions(+), 1 deletion(-)
create mode 100644 learn.txt