1

I have project files with strings that switch between empty and a list of interface names every couple of saves. Some of these files are tens of thousands of lines long, which creates massive diffs that make it difficult to find actual changes. I want to automatically filter out these changes when staging files.

The strings in question are of the format - m_str = "";, where the string is either empty or populated with a list of interface names. Occasionally this string is long enough that it gets broken across multiple lines.

I tried creating a patch by running a python script on the diff, but the patch becomes corrupt if the line numbers change from reverting changes to a multi-line string. I've also tried git diff -G'm_str', which didn't work for me (possibly something with my tools being on Windows).

I may be able to write a program that can automatically run git checkout -p on the file and revert any hunks matching a regex, but that seems unnecessarily difficult.

I've also looked into using a smudge filter, but that still leaves me with the issue of reverting only those lines.

Is there a way to checkout hunks of a file via a script, or otherwise ignore changes matching a certain pattern in Git? If it helps, the offending software is IBM Rational Rhapsody.

codehearts
  • 483
  • 1
  • 9
  • 16
  • Would https://stackoverflow.com/a/17827747/6309 help? – VonC Oct 21 '17 at 07:10
  • That question is asking about headers, but m_str occurs throughout the file. Line numbers may change and m_str lines may become multi-line or single-line, so the only way to identify unwanted changes is to look at the diff. – codehearts Oct 22 '17 at 03:41
  • As long as you can script it, that means a content filter driver can be applied. – VonC Oct 22 '17 at 03:44
  • Is it possible to factor out the volatile parts into separate files? Then they can be put into `.gitignore`. – Lawrence D'Oliveiro Oct 24 '17 at 04:49
  • I was able to write a Python script which takes the diff output and removes the offending hunks, updating the rest of the line numbers. I'm now looking into automatically running that as a hook or filter – codehearts Oct 24 '17 at 18:58

0 Answers0