6

Is it possible to get a report from git diff or related commands that excludes a certain category of change?

I've been asked to review a change where a huge number of files have undergone the equivalent of s/2016/2017/g. (We upgraded a third-party jar and as a result many of our imports now reference a different package.)

Are there options for viewing this diff from the command line but suppressing all changes that just consist of something like the following, so that I can focus on any logic changes?

Ignore:

-import com.example.2016_2.util.Utility
+import com.example.2017_2.util.Utility

Keep:

-Utility util = new Utility();
+Utility util = Utility.create();

If the answer is to write my own script and integrate via git diff --porcelain or by setting GIT_EXTERNAL_DIFF, I am certainly game; just wondering if

  1. this is supported out of the box and somehow I missed it in the man page;
  2. there are other git diff* commands I can use for this;
  3. if an appropriate diff executable already exists that I can provide via GIT_EXTERNAL_DIFF
2
  • --word-diff and --word-diff-regex may help by just highlighting changes on 2016/2017 without showing the full line as changed. Commented Oct 25, 2018 at 17:46
  • I was about to suggest something along the lines of git diff -G<regexp>, but while it's a great tool to select for some string, excluding one is a lot trickier with regexes. Commented Jul 4 at 12:04

1 Answer 1

0

There are plenty of way to diff files, git diff is fine but there are others. Faced with the same task, I would:

  • check out the code with the later changes
  • copy the whole code tree in another directory
  • revert the 2016/2017 change in that copy
  • in the git tree, check out the historic commit
  • do a recursive comparison between the two trees (BeyondCompare on Windows, kdiff3 on Linux)
2
  • I would do the same but just using git: create a new, temporary branch based on new, revert the substitution commit and compare to old. That way git can help by detecting moves/renames AND you can use your IDE.
    – A.H.
    Commented Sep 18, 2018 at 20:14
  • 1
    "copy the whole code tree in another directory" you can use git worktree feature for that Commented Oct 25, 2018 at 17:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .