跟着廖雪峰的git教程学习(2)时光机穿梭(三)管理修改
来源:互联网 发布:泓樽付是网络传销吗 编辑:程序博客网 时间:2024/05/13 16:31
现在,假定你已经完全掌握了暂存区的概念。下面,我们要讨论的就是,为什么Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件。
你会问,什么是修改?比如你新增了一行,这就是一个修改,删除了一行,也是一个修改,更改了某些字符,也是一个修改,删了一些又加了一些,也是一个修改,甚至创建一个新文件,也算一个修改。
为什么说Git管理的是修改,而不是文件呢?我们还是做实验。第一步,对hello.html做一个修改,比如加一行内容:
<!DOCTYPE html><html><head><title>hello</title></head><body> hello world! and i love myself~ you know? and I love my parents too.</body></html>
然后,添加:
$ git add hello.htmlzuo@zuo-PC MINGW32 /d/mygit (master)$ git statusOn branch masterYour branch is ahead of 'BigPauZ/master' by 1 commit. (use "git push" to publish your local commits)Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: hello.html
然后,再修改hello.html:
<!DOCTYPE html><html><head><title>hello</title></head><body> hello world! I love myself~ you know? and I love my parents too. I wish I love the people love me too~ </body></html>
提交:
$ git commit -m "i love the people love me too"[master 5368cc6] i love the people love me too 1 file changed, 1 insertion(+)
提交后,再看看状态:
$ git statusOn branch masterYour branch is ahead of 'BigPauZ/master' by 2 commits. (use "git push" to publish your local commits)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: hello.htmlno changes added to commit (use "git add" and/or "git commit -a")
咦,怎么第二次的修改没有被提交?
别激动,我们回顾一下操作过程:
第一次修改 -> git add
-> 第二次修改 -> git commit
你看,我们前面讲了,Git管理的是修改,当你用git add
命令后,在工作区的第一次修改被放入暂存区,准备提交,但是,在工作区的第二次修改并没有放入暂存区,所以,git commit
只负责把暂存区的修改提交了,也就是第一次的修改被提交了,第二次的修改不会被提交。
提交后,用git diff HEAD -- hello.html
命令可以查看工作区和版本库里面最新版本的区别:
$ git diff HEAD -- hello.htmldiff --git a/hello.html b/hello.htmlindex 27a5b65..be5fc4b 100644--- a/hello.html+++ b/hello.html@@ -1,10 +1,11 @@-<<!DOCTYPE html>+<!DOCTYPE html> <html> <head> <title>hello</title> </head> <body>- hello world! and i love myself~ you know?+ hello world! I love myself~ you know? and I love my parents too.+ I wish I love the people love me too~ </body> </html>\ No newline at end of file
可见,第二次修改确实没有被提交。
那怎么提交第二次修改呢?你可以继续git add
再git commit
,也可以别着急提交第一次修改,先git add
第二次修改,再git commit
,就相当于把两次修改合并后一块提交了:
第一次修改 -> git add
-> 第二次修改 -> git add
-> git commit
好,现在,把第二次修改提交了,然后开始小结。
小结一下:
现在,我又理解了Git是如何跟踪修改的,每次修改,如果不add
到暂存区,那就不会加入到commit
中。
- 跟着廖雪峰的git教程学习(2)时光机穿梭(三)管理修改
- 跟着廖雪峰的git教程学习(2)时光机穿梭(四)撤销修改
- 跟着廖雪峰的git教程学习(2)时光机穿梭
- 跟着廖雪峰的git教程学习(2)时光机穿梭(一)版本回退
- 跟着廖雪峰的git教程学习(2)时光机穿梭(二)工作区和暂存区
- Git教程:时光机穿梭
- Git教程:时光机穿梭
- git 时光机穿梭(三)
- 时光机穿梭---管理修改
- 跟着廖雪峰的git教程学习(1)创建版本库
- Git教程(1)-创建版本库+时光机穿梭
- Git学习(廖雪峰的Git教程)笔记2
- ubuntu第二、三天(时光穿梭机)--学习资源来自廖雪峰博客
- Git 时光机穿梭
- git学习笔记--时光穿梭机
- Git学习(廖雪峰的Git教程)笔记
- git学习(廖雪峰的git教程)笔记 一
- git操作---时光机穿梭
- c 笔记
- Lua中的metatable详解
- 非常实用的30天学习30种技术
- vim编码转换和文件模式类型转换
- 进制转换
- 跟着廖雪峰的git教程学习(2)时光机穿梭(三)管理修改
- 今天遇到的异常,处理了很长时间
- C#版三层登录
- hdu 1058 Humble Numbers (动态规划)
- BZOJ_P3345 PKU2914 Minimum Cut(网络流最小割)
- ScrollView的contentSize属性 与 AutoLayout(Masonry布局)
- java中的Date日期格式转换之二
- Sublime Text 3 安装Package Control
- 通过Toast“打招呼”