git diff 查看文件差异

搬瓦工机场JMS

git diff 命令用于对比文件差异,能够看到哪些文件进行了修改,新增了多少行,删除了多少行,也能对比不同版本、不同tag,甚至不同commit 之间的差异,功能非常强大。
1、差异统计
常用示例:git diff –stat
–stat 参数表示统计汇总,比如对代码进行一通修改后,想了解一共修改了多少个文件,新增了多少行,删除了多少行,就可以使用 git diff –stat,将所有变更信息统计出来,如下所示:
$ git diff –statREADME  | 7 +++++–VERSION | 1 +2 files changed, 6 insertions(+), 2 deletions(-)
常用示例:git diff — test.txt
— test.txt 表示具体某个文件的差异,不加 — 具体文件,显示所有差异。
2、两次提交之间的差异
(1)统计两次提交之间的差异git diff –stat  commit_id1 commit_id2   
(2)统计两次提交之间某个文件的差异git diff –stat  commit_id1 commit_id2 — test.txt
(3)查看两次提交之间某个文件的差异明细git diff commit_id1 commit_id2 — test.txt

3、两个分支的差异
统计汇总:git diff –stat branch1 branch2git diff –stat branch1 branch2 — test.txt
差异明细:git diff branch1 branch2 — test.txt
远程分支也可以对比差异:git diff –stat remotes/origin/branch1 remotes/origin/branch2git diff –stat remotes/origin/branch1 remotes/origin/branch2 — test.txtgit diff remotes/origin/branch1 remotes/origin/branch2 — test.txt

4、两个标签(tag)的差异
统计汇总:git diff –stat tag1 tag2git diff –stat tag1 tag2 — test.txt
差异明细:git diff tag1 tag2 — test.txt

5、前2次提交的某个文件差异
git diff head~ head test.txt
head表示最后一次的提交,head~表示最后一次提交之前的提交。

未经允许不得转载:搬瓦工VPS_美国VPS » git diff 查看文件差异

赞 (0) 打赏

相关推荐

    暂无内容!

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏