Commiting Patches with CVS

Motivation

Have you ever wanted to commit only some of the changes that you've made to few files, but not, for example, the debug code that you added to get it to work? Still, you'd like to keep that debug code in your working directory, you just don't want to check it in.

Do you like to check in only independent and related changes in each commit even though you may be working on more than one thing at once?

Have you wanted to makes a quick change to a file before checking it in, but still have the old version in your working directory?

If so, then cvs-commit-patch and its emacs interface cvs-commit-patch-buffer can help make this process as simple and easy as editing a diff buffer in emacs.

This code has worked reliably for years, but if you happen to use other revision control systems as well you might consider using it's replacement commit-patch which supports git, subversion, darcs and mercurial as well as CVS.

The program: cvs-commit-patch

cvs-commit-patch is an shell script that commits a patch (as generated by diff(1)) to a CVS repository. It It requires bash(1) and a few utilities from the patchutils distribution.

The emacs Interface: cvs-commit-patch-buffer.el

cvs-commit-patch-buffer.el is an emacs interface to cvs-commit-patch. It allows you to just hit C-c C-c in any patch buffer to apply and commit only the changes indicated by the patch, regardless of the changes in your working directory.

One method of working with cvs-commit-patch-buffer is to just M-x vc-diff a file then kill, split or edit the resulting hunks and to then hit C-c C-c to commit the patch. The other is to use PCL cvs mode (M-x cvs-status) to tag many files and then to diff them into a buffer which can again be edited and committed.

Hints for editing a patches in emacs

Once you've got a patch in a buffer the first thing you'll want to do is remove hunks of code you don't want to check in. Use M-k to delete the current hunk and M-n and M-p to move between hunks. The real power of emacs diff mode shows when you need to edit hunks, say to remove a debug print from a hunk you do want to check in. A quick C-k will remove the added lines leaving the rest of the hunk to be checked in. emacs will update the required line counts in the hunk headers for you. You can even split a hunk in two using C-c C-s. Remember that patch likes there to be 3 lines of context at the beginning and end of a patch.