ma11hew28
ma11hew28

Reputation: 126507

git diff: ignore renaming of variables

While doing some refactoring, I renamed a variable from oldName to newName. Is there a way to tell the git diff command to ignore differences where oldName is now newName? I want to do this to focus in on only the other non-trivial changes. If this is possible, can I also specify more than one variable renaming to ignore, e.g., ignore changes from oldName1 to newName1 and from oldName2 to newName2 ... ?

Upvotes: 2

Views: 1187

Answers (3)

Slaven Rezić
Slaven Rezić

Reputation: 11

You want to use the -I option of diff? Here's a way how to do this:

    env GIT_EXTERNAL_DIFF='perl -e "system(qw{diff -I the_pattern_to_ignore -u}, @ARGV[0,1])"' git diff

perl is needed here to throw away the extra arguments git provides to the external diff program.

Upvotes: 1

Seth Robertson
Seth Robertson

Reputation: 31471

He is very correct, but of course you can grep the output of diff. Not the same thing, but depending on the magnitude of the change, perhaps usable.

git diff | egrep -v 'oldName|newName' | egrep '^[+-]'

In general, you should try to have your commits be one commit per concept. You can also split your pre-commits using git add -p.

Upvotes: 2

ma11hew28
ma11hew28

Reputation: 126507

OK. selckin in Git's IRC channel told me that it's not possible.

Upvotes: 0

Related Questions