📢 Actions Speak Louder Than Words!

Patching cvs files using patch manually and how to revert it

Posted: Sep 22, 2020 | Reading time: 3 min

Assalamualaikum and hello everyone!

Today, I gonna put my note how to patch file using “patch” (linux utility tool). Have you using it? Well, please read https://linux.die.net/man/1/patch if you are looking for standard manual from man pages.

I know it already 2020 and yes, someone like me are still using CVS.

CVS (Concurrent Version Control) is very old source code control but it still use nowadays for certain project, even BSD ports still using CVS. To be honest, I don’t like CVS but because it they only SCM (source control management) tool for certain project.


So my project is microservices not monolith. Thus compiled services running inside server and we also store source code (checkout from cvs) inside the same server.

I have option todo coding on my Eclipse IDE locally and commit changes on cvs server and update (pull) changes on production/testing server, but sometimes I don’t want to commit yet. I don’t like half-baked code committed into branches. It will be dangerous and immature (not finalize code yet).


As solution, i will use patch to solve this issue. First, grab the changes as patch using command cvs diff -N -u -l "file_name_here" or via from eclipse ide (setting as diff output as Unified and patch root as project)

You may get something like this as result

cvs diff -N -u -l "/dev-ops-tools/src/com/ssp/support/commons/connection/ConnectionController.java"
    Index: src/com/ssp/support/commons/connection/ConnectionController.java
    RCS file: /cvs/dev-ops-tools/src/com/ssp/support/commons/connection/ConnectionController.java,v
    retrieving revision 1.5
    diff -u -r1.5 ConnectionController.java
    --- src/com/ssp/support/commons/connection/ConnectionController.java	8 Mar 2016 16:08:05 -0000	1.5
    +++ src/com/ssp/support/commons/connection/ConnectionController.java	22 Sep 2020 03:32:09 -0000
    @@ -61,6 +61,7 @@
         } else {
    +      LOG.info("ROB WAS HEREZ");
           LOG.info("connections.xml file found");
         return pathname;

warning “Take note” From my example above, look at line num 7-8 (lets just called it as target file). Please change it manually if file are location inside server are different with your development enviroment.

Copy the diff output (if from my example, copy from line 2-16 only) as put on file (as example I will call it as patch.diff) inside you server. Make use location of target file are correct and match from where patch.diff file are stored.

Now we can simulate / test it first (no file changes) using patch -b --dry-run -p0 < patch.diff and if everything ok, then do the real patch with patch -b -p0 < patch.diff.

$ patch -b -p0 < patch.diff
patching file src/com/ssp/support/commons/connection/ConnectionController.java

The parameter -b is additional but it better to always use it because it will create backup of file with extension *.orig and you can rollback / revert to origin state if after patched file and thing are not working as expected. so yes, wiht -b parameter, it will create backup for you. (you can search it with find . -name *.orig command)

Undo, revert, rollback? yes.. just simple run patch -R -p0 < patch.diff from terminal 😄


Discussion and feedback

You can use utterances provided below to post comment on behalf using Github account. Alternatively, you can just send a (plain text) email to my private email or personal public mailing list. In a few cases and on certain time, I just don’t have time to moderate them. Please read terms-of-service (ToS) for details.