Is there a way to get a patch that never executes, only modifies the working copy?

I would like to modify the test for comment in some additional code:

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

That is, when I create locally, I would like to enable SimpleMonitor, but I always want the tested code to leave it in the comments. SimpleMonitor provides some detailed information about what is going on inside my test.

Of course, I just can't add this change to commit.

Is there a way with git that I can always rule out this change even when using 'git add.' or 'git add -A', etc., so that git skips this change?

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

+4
source share
1 answer

You can declare a content filter driver ("clean" script) for your file, which automatically, when checked, comments on the correct line.
This is done in the file .gitattributes: see, for example, " Does it have an .gitignoreequivalent for files with a controlled version? ".

clean

(Image from Git Attributes Settings from Git Book )

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

You may have a <filterscript>version in your repo.

+3
source

Source: https://habr.com/ru/post/1545388/


All Articles