按变化类型过滤git diff [英] Filter git diff by type of change

查看:105
本文介绍了按变化类型过滤git diff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有限制 git diff 更改文件的方法?



我想查看两个提交之间的差异,但排除在其中一个或另一个中不存在的路径(添加/删除)。下面的Perl单行说明了我想要的大部分内容:

  git diff master .. | perl -lnwe'打印除非^ ^(new | deleted)文件/../^ diff /而不是/ ^ diff /'

但是,对于新的或删除的文件,会留下 diff --git a / path b / path 行。另外,如果我不需要解析就更好了(例如,如果任何大块包含任何匹配/ ^ diff /的东西,也会失败)。

另外一种替代方法我试过是:

  git diff --name-status(args)| perl -lnwe'打印如果s / ^ M \s + //'| xargs git diff(args) -  

它的输出效果更好,但它仍然令人感到ha。。您正在寻找 - diff-filter = M 以仅显示

解决方案文件* M *在两个分支之间进行了修饰。

man git-diff



$ b

- diff-filter = [ACDMRTUXB *]

p>


  • A 新增
  • C 已复制

  • D 已删除
  • 修改

  • R 更名

  • T 的类型(模式)已更改

  • U 未合并
  • >
  • X 未知

  • B 他们的配对破碎

  • * 全部或无所有


    可以使用任何过滤字符的组合。



    当组合中添加*(全部或无)时,如果有任何文件与$中的其他条件相匹配,则所有路径均为
    b $ b比较;如果没有符合其他条件的文件,则不会选择



Is there a way to limit git diff to changed files?

I'd like to see the differences between two commits, but exclude paths that don't exist in one or the other (additions/deletions). The following Perl one-liner illustrates most of what I want:

git diff master.. | perl -lnwe 'print unless /^(new|deleted) file/../^diff/ and not /^diff/'

But that leaves diff --git a/path b/path lines for the files that were new or deleted. Plus it'd be much nicer if I didn't have to parse (also fails if any hunk contains anything matching /^diff/, for example).

Another alternative I tried was:

git diff --name-status (args) | perl -lnwe 'print if s/^M\s+//' | xargs git diff (args) --

Its output is better, but it still feels hackish.

解决方案

You are looking for --diff-filter=M to show only files *M*odified between the two branches.

From man git-diff

--diff-filter=[ACDMRTUXB*]

Select only files that are

  • A Added
  • C Copied
  • D Deleted
  • M Modified
  • R Renamed
  • T have their type (mode) changed
  • U Unmerged
  • X Unknown
  • B have had their pairing Broken
  • * All-or-none

Any combination of the filter characters may be used.

When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.

这篇关于按变化类型过滤git diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆