0

how should I return names of the changed files ignoring those where the only change is this java comment "// Generated on: ..."

I was triing something like this git diff HEAD~1 -G '^(?!\/\/ Generated on.*$).*' --name-only, but it is complaining fatal: invalid regex: Invalid preceding regular expression.

Basically I am quite new to regex so could someone help me to correct the regex expression?

Jakub Znamenáček
  • 766
  • 1
  • 4
  • 18
  • 2
    According to https://stackoverflow.com/a/39790343/3216427, Git uses POSIX extended regular expressions, which don't support the `(?...)` syntax you're trying to use. I'm not sure "does not contain string X" can be expressed with POSIX EREs, to be honest. – joanis Jan 26 '22 at 14:09
  • I was able to achieve if with `^([^\/]|\/($|[^\/]|\/($|[^ ]| ($|[^G]|G($|[^e]|e($|[^n]|n($|[^e]|e($|[^r]|r($|[^a]|a($|[^t]|t($[^e]|e($[^d]|d($[^ ]| ($[^o]|o($|[^n]|n($[^:])))))))))))))))).*` but I would not like to do it again :D. I hope there is better solution. – Jakub Znamenáček Jan 27 '22 at 13:49
  • Wow, that is horrendous, but good for you for getting that RE written correctly! – joanis Jan 27 '22 at 17:21

1 Answers1

0

Try git diff HEAD~1 -I'^\/\/ Generated on', which ignores the entire line whenever it starts with that string. The -I flag enables somewhat simpler regex.

from the docs about Git-diff:

-I<regex>
--ignore-matching-lines=<regex>

    Ignore changes whose all lines match <regex>. This
    option may be specified more than once.
Kay V
  • 3,738
  • 2
  • 20
  • 20