Git — 管理修改

管理修改

GIt 比其他版本控制系统设计得优秀,因为 Git 跟踪并管理的是修改,而非文件。

验证

  1. 对 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
    
  2. 然后,执行 git add

    $ git add readme.txt
    $ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       modified:   readme.txt
    #
    
  3. 再修改 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.
    
  4. 执行 git commit 提交;

    $ git commit -m "git tracks changes"
    [master 519219b] git tracks changes
     1 file changed, 1 insertion(+)
    
  5. 再查看状态;

    $ 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 add -> 第二次修改 -> git commit
原因

  • git add:把工作区的修改被放入暂存区;
  • git commit:只负责把暂存区的修改提交;

所以,第一次修改提交了,第二次修改并未被提交。

命令查看 git 工作区和版本库的区别

执行 git diff HEAD – readme.txt 可以查看工作区和版本库的区别

$ git diff HEAD -- readme.txt 
diff --git a/readme.txt b/readme.txt
index 76d770f..a9c5755 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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值