如何使Git diff忽略版本号更改? [英] How do I make Git diff ignore version number changes?

查看:117
本文介绍了如何使Git diff忽略版本号更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以消除Git差异中版本号更改带来的噪音这个?具体来说,如果一行仅包含从一个数字到另一个数字的更改,我可以设置Git diff来忽略它吗?

Is there a way to remove version number change noise from a Git diff like this one? Specifically if a line only contains changes from one number to another can I set up Git diff to ignore it?

推荐答案

可以使用 git-diff --word-diff-regex = [^ 0-9] 请参阅[^ 0-9]进行操作)。对于更复杂的模式,您将需要更复杂的正则表达式,但是递归除外正则表达式可以实现所有功能

I think this can be achieved using git-diff --word-diff-regex=[^0-9] (see [^0-9] in action). For a more complex pattern you'll need a more complex regex but, except recursion, everything is possible with regex.

来自 Git-git-diff -word-diff-regex 文档


-word-diff-regex =

使用<正则表达式>决定单词是什么,而不是将
非空白的运行视为单词。除非已启用
,否则还暗示-word-diff

Use < regex > to decide what a word is, instead of considering runs of non-whitespace to be a word. Also implies --word-diff unless it was already enabled.

所有非-<的重叠匹配正则表达式>被认为是一个单词。这些匹配之间的任何内容都被视为空格,并且为了发现差异而忽略了(!)
您可能希望在
| [^ [:space:]之后附加] 到您的正则表达式中,以确保它
与所有非空白字符匹配。包含换行符
的匹配项在换行符处被静默截断(!)。

Every non-overlapping match of the < regex > is considered a word. Anything between these matches is considered whitespace and ignored(!) for the purposes of finding differences. You may want to append |[^[:space:]] to your regular expression to make sure that it matches all non-whitespace characters. A match that contains a newline is silently truncated(!) at the newline.

例如,-word-diff- regex =。会将每个字符视为一个单词
,并相应地逐字符显示差异。

For example, --word-diff-regex=. will treat each character as a word and, correspondingly, show differences character by character.

regex也可以可以通过差异驱动程序或配置选项进行设置,
参见 gitattributes [5] git-config [1] 。给它
显式覆盖任何差异驱动程序或配置设置。 Diff
驱动程序将覆盖配置设置。

The regex can also be set via a diff driver or configuration option, see gitattributes[5] or git-config[1]. Giving it explicitly overrides any diff driver or configuration setting. Diff drivers override configuration settings.



另请参见




  • Git-git-diff -word-diff

  • 这篇关于如何使Git diff忽略版本号更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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