Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

git - Is there a way to have a patch that is never commited, only changes the working copy?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...