我们要习惯于每进行一个操作,就查看一下仓库的状态,使用的命令就是:
git status
【修改文件之后,仓库状态】
$ 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
#
no changes added to commit (use "git add" and/or "git commit -a")
下面,我们分析下这个命令的输出都是什么含义:
1、On branch master:表示当前的操作是在仓库的master分支上;
2、Changes ont staged for commit:表示当前的修改还没有通过add命令将其放到stage上(只有在stage上的文件才能被commit到仓库);
3、use "git add <file>...”:表示你可以通过add命令将“修改”update到stage上,以便之后将其commit到仓库。
4、use "git checkout -- <file>..." :表示你如果对当前的修改不满意,可以将修改撤销,方法就是执行git checkout --<file>命令(其实是将仓库上的文件checkout出来覆盖当前working directory中的文件)。
5、modified: readme.txt:表示当前的readme.txt被修改了。
【add到stage上之后,仓库状态】
执行完add之后,所做的“修改”就被放到了stage上了,在stage上的“修改”可以随时被commit到仓库。这时查看仓库状态:
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: readme.txt
#
下面,我们分析这个命令的输出含义:
1、On branch master:表示当前的操作是在仓库的master分支上;
2、(use "git reset HEAD <file>..." to unstage):表示可以讲当前的修改从stage上撤下来,执行的命令就是git reset HEAD <file>。
3、Changes to be committed: modified: readme.txt:将要被提交的修改包括readme.txt
【commit之后,仓库的状态】
执行完add之后,就可以commit到仓库了。commit之后的仓库状态:
$ git status
# On branch master
nothing to commit (working directory clean)
这个命令的输出结果含义是:
当前没有需要提交的修改,而且,工作目录是干净(working directory clean)的。