zoukankan      html  css  js  c++  java
  • Git:git diff 命令详解

    工作目录 vs 暂存区

    $ git diff <filename>
    

    意义:查看文件在工作目录与暂存区的差别。如果还没 add 进暂存区,则查看文件自身修改前后的差别。也可查看和另一分支的区别。

    $ git diff <branch> <filename>
    

    暂存区 vs Git仓库

    git diff --cached <filename>
    

    意义:表示查看已经 add 进暂存区但是尚未 commit 的内容同最新一次 commit 时的内容的差异。 也可以指定仓库版本:

    git diff --cached <commit> <filename>
    

    工作目录 vs Git仓库

    git diff <commit> <filename>
    

    意义:查看工作目录同Git仓库指定 commit 的内容的差异。 <commit>=HEAD 时:查看工作目录同最近一次 commit 的内容的差异。

    Git仓库 vs Git仓库

    git diff <commit> <commit>
    

    意义:Git仓库任意两次 commit 之间的差别。

    扩展:

    以上命令可以不指定 <filename>,则对全部文件操作。 以上命令涉及和 Git仓库 对比的,均可指定 commit 的版本。

    • HEAD 最近一次 commit
    • HEAD^  上次提交
    • HEAD~100 上100次提交
    • 每次提交产生的哈希值

    最佳实践

    准备工作:

    • 新建文件 test.txt;
    • 追踪文件:git add test.txt;
    • 首次提交:git commit -m "Create file test.txt"

    开始测试:

    1、修改文件内容,例如添加一行“000” 2、查看修改:git diff test.txt

    此时由于没有向暂存区暂存此修改,此时作用是查看工作目录文件的修改。

    3、提交一次:git commit -m "add line 000" 4、修改文件内容,例如添加一行“111” 5、暂存此次修改:git add test.txt,不作 commit 6、再次修改文件夹内容,例如添加一行“222” 7、查看修改:git diff test.txt

    此时查看文件在工作目录(222)与暂存区(111)的差别。

    其它命令自行测试

  • 相关阅读:
    springboot springcloud zuul 过滤器
    springboot springcloud eureka 熔断器
    javaweb servlet filter
    maven nexus 搭建私服(二)
    springboot springcloud zuul 网关入门
    springboot springcloud 配置中心
    springboot springcloud eureka 入门
    java rabbitmq
    java jvm调优
    maven nexus 搭建私服(一)
  • 原文地址:https://www.cnblogs.com/xuxiuxiu/p/8522594.html
Copyright © 2011-2022 走看看