分支和 HEAD 的概念我们以后再讲。
前面讲了我们把文件往Git版本库里添加的时候,是分两步执行的:
第一步是用 git add 把文件添加进去,实际上就是把文件修改添加到暂存区;
第二步是用 git commit 提交更改,实际上就是把暂存区的所有内容提交到当前分支。
因为我们创建Git版本库时,Git自动为我们创建了唯一一个 master 分支,所以,现在, git commit 就
是往 master 分支上提交更改。
你可以简单理解为,需要提交的文件修改通通放到暂存区,然后,一次性提交暂存区的所有修改。
俗话说,实践出真知。现在,我们再练习一遍,先对 readme.txt 做个修改,比如加上一行内容:
然后,在工作区新增一个 LICENSE 文本文件(内容随便写)。
先用 git status 查看一下状态:
Git非常清楚地告诉我们, readme.txt 被修改了,而 LICENSE 还从来没有被添加过,所以它的状态是
Untracked 。
现在,使用两次命令 git add ,把 readme.txt 和 LICENSE 都添加后,用 git status 再查看一下:
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
1
2
3
$ 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")
1
2
3
4
5
6
7
8
9
10
11
12
13
14