• Git 学习札记(三)关于 git diff 操作及其参数


    Git 学习札记(三)

    关于Git中diff操作的比较

    git diff ,git diff –cached,git diff –staged,git diff HEAD – filename

    先做一个实验:

    chia@edogawachia-sphinx:~/mygit$ cat readme.txt 
    This is a readme file
    created by E.Chia 2018/02/06
    modified by E.Chia 1st time
    chia@edogawachia-sphinx:~/mygit$ git status 
    位于分支 master
    无文件要提交,干净的工作区
    chia@edogawachia-sphinx:~/mygit$ sudo vim readme.txt 
    chia@edogawachia-sphinx:~/mygit$ cat readme.txt 
    This is a readme file
    created by E.Chia 2018/02/06
    modified by E.Chia 1st time
    add this to show staged version
    chia@edogawachia-sphinx:~/mygit$ sudo git add 'readme.txt'
    chia@edogawachia-sphinx:~/mygit$ git status
    位于分支 master
    要提交的变更:
      (使用 "git reset HEAD <文件>..." 以取消暂存)
    
        修改:     readme.txt
    
    chia@edogawachia-sphinx:~/mygit$ sudo vim readme.txt 
    chia@edogawachia-sphinx:~/mygit$ cat readme.txt 
    This is a readme file
    created by E.Chia 2018/02/06
    modified by E.Chia 1st time
    add this to show staged version
    add this to show working directory version

    这样三个区域的版本都不一样了,branch中的最短,stage暂存区的有一句add this to show staged version,工作区的多一句 add this to show working directory version。

    下面测试各种 diff 的用法:

    chia@edogawachia-sphinx:~/mygit$ git diff
    diff --git a/readme.txt b/readme.txt
    index 3e42036..e24b3e0 100644
    --- a/readme.txt
    +++ b/readme.txt
    @@ -2,3 +2,4 @@ This is a readme file
     created by E.Chia 2018/02/06
     modified by E.Chia 1st time
     add this to show staged version
    +add this to show working directory version
    chia@edogawachia-sphinx:~/mygit$ git diff --cached
    diff --git a/readme.txt b/readme.txt
    index d995350..3e42036 100644
    --- a/readme.txt
    +++ b/readme.txt
    @@ -1,3 +1,4 @@
     This is a readme file
     created by E.Chia 2018/02/06
     modified by E.Chia 1st time
    +add this to show staged version
    chia@edogawachia-sphinx:~/mygit$ git diff --staged
    diff --git a/readme.txt b/readme.txt
    index d995350..3e42036 100644
    --- a/readme.txt
    +++ b/readme.txt
    @@ -1,3 +1,4 @@
     This is a readme file
     created by E.Chia 2018/02/06
     modified by E.Chia 1st time
    +add this to show staged version
    chia@edogawachia-sphinx:~/mygit$ git diff HEAD
    diff --git a/readme.txt b/readme.txt
    index d995350..e24b3e0 100644
    --- a/readme.txt
    +++ b/readme.txt
    @@ -1,3 +1,5 @@
     This is a readme file
     created by E.Chia 2018/02/06
     modified by E.Chia 1st time
    +add this to show staged version
    +add this to show working directory version
    chia@edogawachia-sphinx:~/mygit$ git diff HEAD -- readme.txt
    diff --git a/readme.txt b/readme.txt
    index d995350..e24b3e0 100644
    --- a/readme.txt
    +++ b/readme.txt
    @@ -1,3 +1,5 @@
     This is a readme file
     created by E.Chia 2018/02/06
     modified by E.Chia 1st time
    +add this to show staged version
    +add this to show working directory version

    可以看到,git diff 比较工作区和暂存区,git diff –cache (或者–staged)比较版本和暂存区,git diff HEAD – filename 比较branch上的HEAD指向的版本与工作区的区别(这里的HEAD可以是任意指针,即用哈希值表示的 commit id ,或者HEAD~等)。这样三者中的任意两者都可以比较了。

    2018-02-07 16:25:46

  • 相关阅读:
    HttpClientUtil的工具类请求三方API
    Linux下使用docker搭建ftp服务器
    Springboot2.0.4整合Mybatisplus
    Springboot前后端分离项目,配置跨域
    Nokia S40 系统配置
    "Your profile could not be opened correctly" Google Chromium Browser 错误纠正
    CLR AppDomain
    iTunes下载提速
    Which Programming Language?
    linux下制作软盘镜像文件
  • 原文地址:https://www.cnblogs.com/morikokyuro/p/13256819.html
Copyright © 2020-2023  润新知