Git教程-理解Git跟踪修改

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值