Git学习之旅–独特的跟踪与管理
上一篇介绍了git暂存区的概念,这一篇将介绍git 比其它版本控制系统优秀的原因
git 版本控制系统最奇特的地方在于它跟踪和管理的不是文件本身,而是对文件修改的这个操作。
之前的git add 和git commit 为什么一定要修改一次提交一次?
来让我们试验一下:
首先对文件 file1.txt 进行修改
这是第一个文件 two six +
记得保存!!!
执行git add 加入暂存区
$ git add file1.txt
先不急着提交,我们再次对这个文件进行修改
这是第一个文件 two six + five
保存!!!
这次我们进行提交
$ git commit -m 'add + five'
[master b8753c7] add + five
1 file changed, 1 insertion(+), 1 deletion(-)
让我们看一下状态
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file1.txt
no changes added to commit (use "git add" and/or "git commit -a")
不是提交之后工作区就干净了吗?这是肿么肥事?
查看一下提交之后跟原文件的区别
$ git diff
diff --git a/file1.txt b/file1.txt
index 831c25a..6cc537a 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1 +1 @@
-这是第一个文件 two six +
\ No newline at end of file
+这是第一个文件 two six + five
\ No newline at end of file
为什么第二次修改没有提交呢?
别急,一起回顾一下
你会发现,我们只是把第一次修改操作放入到了暂存区,而第二次修改操作并没有放入暂存区,commit 只负责把暂存区的修改提交到本地仓库里面。
所以只提交了第一次修改的操作。
因此我们需要把第二次修改操作加入暂存区,再提交到本地仓库
$ git add file1.txt
$ git commit -m 'add five'
[master e41ca86] add five
1 file changed, 1 insertion(+), 1 deletion(-)
再次查看状态
$ git status
On branch master
nothing to commit, working tree clean
可以看到,工作区干净了。