Git入门(6)-管理修改
上节讲到了Git有自己的工作区和缓存区,下面就深入的了解Git是如何跟踪修改的。
做一个实验:假设我们有一个文件readme.txt,里面的内容是
Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage.
我们手动的给readme.txt里加上一行 如下;
Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes.
然后添加一下:
$ git add readme.txt $ git status # On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: readme.txt
#
然后我们再手动修改一下,在最后加上of files如下:
Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files.
然后直接提交:
$ git commit -m "git tracks changes" [master d4f25b6] git tracks changes1 file changed, 1 insertion(+)
然后看一下状态:
$ 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")
我们会发现,我们第二次的修改没有提交上,这是我们只把第一次修改添加到了缓存区了,而第二次的修改,我们并没有添加到缓存区。
提交后我们可以用
git diff HEAD -- readme.txt
命令可以查看工作区和版本库里面最新版本的区别:
$ git diff HEAD -- readme.txt diff --git a/readme.txt b/readme.txt index 76d770f..a9c5755 100644
--- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@
Git is a distributed version control system.Git is free software distributed under the GPL.Git has a mutable index called stage. -Git tracks changes. +Git tracks changes of files.
通过查看,第二次确实没有改,所有我在修改后,必须要添加到缓存区,一起添加可以,分着添加也可以。
总结: 工作区的东西不会被提交到版本库,加到缓存区的东西可以commit.