如何使'git diff'忽略注释 [英] How to make 'git diff' ignore comments
问题描述
我正在尝试生成在特定提交中更改的文件的列表。问题是,每个文件在文件顶部的注释中都具有版本号-并且由于此提交引入了新版本,这意味着每个文件都已更改。
I am trying to produce a list of the files that were changed in a specific commit. The problem is, that every file has the version number in a comment at the top of the file - and since this commit introduces a new version, that means that every file has changed.
我不在乎更改的注释,因此我想让 git diff
忽略所有与 ^ \匹配的行\s * \ *。* $
,因为这些都是注释(/ * * /的一部分)。
I don't care about the changed comments, so I would like to have git diff
ignore all lines that match ^\s*\*.*$
, as these are all comments (part of /* */).
我找不到任何方法 git diff
忽略特定的行。
I cannot find any way to tell git diff
to ignore specific lines.
我已经尝试设置textconv属性,以使Git在将文件进行区分之前将文件传递给sed。 ,以便sed可以删除有问题的行-问题在于, git diff --name-status
实际上并不比较文件,只是比较散列,
I have already tried setting a textconv attribute to cause Git to pass the files to sed before diffing them, so that sed can strip out the offending lines - the problem with this, is that git diff --name-status
does not actually diff the files, just compares the hashes, and of course all the hashes have changed.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
git diff -G <regex>
并指定一个不与您的版本号行不匹配的正则表达式。
And specify a regular expression that does not match your version number line.
这篇关于如何使'git diff'忽略注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!