廖雪峰Git教程笔记(七)管理修改

假设我们已经掌握了暂存区的概念,本节会更深入的理解Git的修改过程。。。。。

廖雪峰官网教程中对修改的定义是:比如你新增了一行,这就是一个修改,删除了一行,也是一个修改,更改了某些字符,也是一个修改,删了一些又加了一些,也是一个修改,甚至创建一个新文件,也算一个修改。

继续跟着官网做实验吧。。。。

在readme里面加一行

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
git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   readme

然后,再次修改readme

cat readme
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 b6eb0ee] git tracks changes
 1 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

no changes added to commit (use "git add" and/or "git commit -a")

发现并没有被提交 还记得吗?如果在暂存区没有东西,都提交到分支的化,那么应该是“On branch master nothing to commit, working tree clean”了。。。。

我们回顾一下整个过程:

第一次修改–>git add –>第二次修改–>git commit

因此,整个过程应该是:

Git 管理的是修改,当你用git add 命令之后,在工作区的第一次修改被放入暂存区,准备提交,但是在工作区的第二次修改并没有放入暂存区,所以,git commit 只负责把暂存区的修改提交了,所以,第一次的修改被提交了,第二次的修改不会被提交。

这里注意,如果不进行git add 直接commit,结果是:

On branch master
Changes not staged for commit:
    modified:   readme

no changes added to commit

因为并没有添加到暂存区

这里查看工作区和版本库的区别:

git diff HEAD -- readme
diff --git a/readme.txt b/readme.txt
index a9c5755..dfc0e83 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.

因此,我们再次添加,再次提交

git add readme
git commit -m "git tracks changes1"
[master 396deb9] git tracks changes1
 1 file changed, 1 insertion(+), 1 deletion(-)

再次查看

On branch master
nothing to commit, working tree clean

小结:如果不add到暂存区,就不会加入大commit中,也就不会更新到版本库中了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值