Patching cvs files using patch manually and how to revert it
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
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
-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 😄