zoukankan      html  css  js  c++  java
  • git diff 命令用法

    理解git diff的前提,首先要理解git中工作区,暂存区,本地版本库的概念,如果头脑中有这些概念,接着往下读。

    git diff test.c 用来查看工作区和暂存区中test.c文件的区别。

    git diff HEAD -- test.c 用来查看工作区和本地版本库中test.c文件的区别。

    eg:

    a. 在工作区中修改文件cfm_test.c,git diff cfm_test.c 和 git diff HEAD --  cfm_test.c 分别输出如下:

    [3me]$ git diff cfm_test.c
    @@ -45,7 +45,11 @@ cfm_test_init ()
       tst->tst_data = XCALLOC (MTYPE_ITUT_CFM_MSG, CFM_TST_PDU_MAX_LENGTH);
       if (!tst->tst_data)
         {
    -      XFREE (MTYPE_ITUT_CFM_MSG, tst->tst_data);
    +#if defined(CONFIG_DS_COVERITY)
    +	XFREE( MTYPE_ITUT_CFM_TST, tst);
    +#else
    +	XFREE (MTYPE_ITUT_CFM_MSG, tst->tst_data);
    +#endif
           return NULL;
         }
     
    [3me]$ git diff HEAD -- cfm_test.c
    @@ -45,7 +45,11 @@ cfm_test_init ()
       tst->tst_data = XCALLOC (MTYPE_ITUT_CFM_MSG, CFM_TST_PDU_MAX_LENGTH);
       if (!tst->tst_data)
         {
    -      XFREE (MTYPE_ITUT_CFM_MSG, tst->tst_data);
    +#if defined(CONFIG_DS_COVERITY)
    +	XFREE( MTYPE_ITUT_CFM_TST, tst);
    +#else
    +	XFREE (MTYPE_ITUT_CFM_MSG, tst->tst_data);
    +#endif
           return NULL;
         }
     
    

    b. 执行git add cfm_test.c,将文件提交到暂存区,输出如下:

    [3me]$ git add cfm_test.c
    [3me]$ git diff cfm_test.c
    [3me]$ git diff HEAD -- cfm_test.c
    @@ -45,7 +45,11 @@ cfm_test_init ()
       tst->tst_data = XCALLOC (MTYPE_ITUT_CFM_MSG, CFM_TST_PDU_MAX_LENGTH);
       if (!tst->tst_data)
         {
    -      XFREE (MTYPE_ITUT_CFM_MSG, tst->tst_data);
    +#if defined(CONFIG_DS_COVERITY)
    +    XFREE( MTYPE_ITUT_CFM_TST, tst);
    +#else
    +    XFREE (MTYPE_ITUT_CFM_MSG, tst->tst_data);
    +#endif
           return NULL;
         }
     

    分析:由于已经将文件提交到暂存区,所以工作区和暂存区中文件无区别,所以 git diff cfm_test.c 无输出内容;由于未提交到本地版本库,工作区和本地版本库文件有区别,所以 git diff HEAD -- cfm_test.c 输出diff内容。

    c. 接着执行git commit 将文件提交到本地版本库,输出如下:

    [3me]$ git commit -m "for source code coverity check."
    [master 444ebb0f84] for source code coverity check.
     1 file changed, 5 insertions(+), 1 deletion(-)
    [3me]$ git diff cfm_test.c
    error: cannot run most: No such file or directory
    [3me]$ git diff HEAD -- cfm_test.c
    error: cannot run most: No such file or directory

    分析:执行 commit 将文件提交到本地版本库, 因此工作区,暂存区,本地库三者之间的内容是一致的,因此git diff 和git diff HEAD 输出均无内容。

  • 相关阅读:
    js中获取页面被卷去的高度等一些属性
    【转】js中cookie的使用详细分析
    2017-3-16 Tsql基础编程 存储过程 触发器 级联删除
    采用ajax请求返回得到json数据,取出具体项却为undefined
    读书笔记-你不知道的JavaScript(上) 【转自 http://muyunyun.cn/】
    AJAX 三级联动
    winform 打印控件
    winform 之MDI容器
    ajax完整版
    【2017-7-17】动软代码生成器 数据库连接 配置失败 解决方法
  • 原文地址:https://www.cnblogs.com/3me-linux/p/6639692.html
Copyright © 2011-2022 走看看