Git教程-理解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.
对其做一个修改:
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,查看git status:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: readme.txt
再修改readme.txt:
$ cat 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 of files.
此时git commit提交,提交的是第一次修改的,也就是提交的是存在了缓存区中的内容
$ git commit -m "git track changes"
[master abc33e9] git track changes
1 file changed, 2 insertions(+), 1 deletion(-)
查看此时的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")
由于第二次的内容在工作区中,不在缓存区,所以显示第二次的修改没有被提交。
用git diff HEAD – readme.txt命令可以查看工作区(第二次修改的)和版本库(第一次修改的)里面最新版本的区别,可见第二次修改确实没有提交
diff --git a/readme.txt b/readme.txt
index db28b2c..9a8b341 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.
\ No newline at end of file
+Git tracks changes of files.
\ No newline at end of file
博客介绍了Git跟踪的是修改而非文件。以readme.txt文件为例,第一次修改后使用git add,再进行第二次修改,git commit提交的是第一次修改内容,因第二次修改在工作区未进缓存区。还提到可用git diff HEAD – readme.txt查看工作区和版本库区别。

5256

被折叠的 条评论
为什么被折叠?



