回顾:
上篇主要讲述的是概念性的东西,比如什么是git的工作区(working directory)和暂存区(stage)以及分支(master)
git与别的版本控制系统的一个不同之处就是有暂存区的概念。
新知识:
假如你继续修改readme.txt文件,新添加了一行内容。
然后git add readme.txt 提交到暂存区。
git status查看版本库当前状态。
改变需要被提交commit。
此时我们继续去修改readme.txt文件,继续添加内容。
提交(commit):
$ git commit -m "git tracks changes"
[master 519219b] git tracks changes
1 file changed, 1 insertion(+)
提交后再次查看状态:
$ git status
On branch master
Changes not staged for commit: 改变没有在暂存区需要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")
第二次的修改没有被提交?why?
第一次修改后 ——> git add ——>第二次修改 ——>git commit
问题出现了,我们第二次修改没有git add 到暂存区。你提交的只是在暂存区里面的修改。所以这才是你每次代码写好之后必须先git add 然后再git commit的根本原因。
用git diff HEAD -- readme.txt
命令可以查看工作区和版本库里面最新版本的区别.
SO:
每次修改,如果不用git add
到暂存区,那就不会加入到commit
中。再次看下这张图吧。