4

I would like to modify a test to comment in some extra code:

-        /*SimpleMonitor monitor = new SimpleMonitor();
-        machine.attachMonitor(monitor);*/
+        SimpleMonitor monitor = new SimpleMonitor();
+        machine.attachMonitor(monitor);

That is, when I am building locally I would like to enable SimpleMonitor, but I always want the checked in code to keep it commented out. SimpleMonitor prints out some verbose information about what is going on internally in my test cases.

Of course I can just never add this change to the commit.

Is there a way with git that I can always exclude this change, even when using 'git add .' or 'git add -A' and so on, such that git will skip over this change?

The idea is that this is a delta that sits on top of a working copy only. If there is some neat trick with stash or using a branch or something else, do please tell me about it.

user2800708
  • 1,890
  • 2
  • 18
  • 31

1 Answers1

3

You could declare for your file a content filter driver ( a 'clean' script) which would automatically, on checkin, comment the right line.
That is done in a .gitattributes file: see for instance "Does .gitignore have an equivalent for version controlled files?".

clean

(image from "Customizing Git Attributes" from the Git Book)

git config filter.<filtername>.clean ./<filterscript>

You can have <filterscript> versioned in your repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, that sounds like it will do the trick. Unlike the other question, I do't have to enforce this on other users either, its just for my local testing. – user2800708 Jun 20 '14 at 14:46
  • @user2800708 yes, that will be local only to your repo, because the `git config` which declares that filter won't impact other repos. So even if the .gitattributes and scripts are in your repo, the filter won't run unless you explicitly declares it in the *local* config of your repo. – VonC Jun 20 '14 at 14:48