Wednesday, 8 August 2007

small commits

Update: I have been informed that git and mercurial have support for the hunk commit feature, excellent! See the comments section if you want to know the details. IIRC, The last time someone talked about this feature was when John Gorzen analyzed his options for another VCS (still now I can't find any reference to this issue).


Lars, darcs allows this and, as a supplement that is missing from any other VCS I know, is the ability to select individually changes in a file. That means you can commit only some of the changes affecting a file and leave others for later commits.

So for this diff:

$ darcs diff -u
diff -rN -u old-asd/asdnbfnd new-asd/asdnbfnd
--- old-asd/asdnbfnd 2007-08-08 18:12:17.000000000 +0300
+++ new-asd/asdnbfnd 2007-08-08 18:12:17.000000000 +0300
@@ -1,3 +1,3 @@
-#!/bin/ash
+#!/bin/sh

-echo "intentionaol spelling error"
+echo "intentional spelling error"

you can do this:

$ darcs rec -m "spelling correction"
hunk ./asdnbfnd 1
-#!/bin/ash
+#!/bin/sh
Shall I record this change? (1/?) [ynWsfqadjkc], or ? for help: n
hunk ./asdnbfnd 3
-echo "intentionaol spelling error"
+echo "intentional spelling error"
Shall I record this change? (2/?) [ynWsfqadjkc], or ? for help: y
Finished recording patch 'spelling correction'

$ darcs rec -m "make the script run on posix shell"
hunk ./asdnbfnd 1
-#!/bin/ash
+#!/bin/sh
Shall I record this change? (1/?) [ynWsfqadjkc], or ? for help: y
Finished recording patch 'make the script run on posix shell'

Of course, being able to unrecord/uncommit or to rollback is a nice thing to have.

4 comments:

Josh Triplett said...

Git has exactly this feature. Try "git add --interactive" (git add -i for short). It allows you to interactively add or remove changes to the index, including all the changes to a file, individual hunks from those changes, or even *part* of those hunks (it will split them into smaller hunks for you).

Anonymous said...

mercurial has the record extension that allows commiting hunks interactively as well.

Unknown said...

'bzr shelve' is similar but better, in that it lets you interactively take the changes you don't want to commit out of your working tree temporarily (for later restoration using 'bzr unshelve'); this means that you can test the change before committing it rather than simply hoping that you extracted the right parts.

The shelf plugin is in the bzrtools package.

Florian Ragwitz said...

although bzr shelve/unshelve sounds nice pretty much every decent vcs can do that.

Just commit your things, move the uncommited changes out of the way (like git stash), test and amend the commit if necessary and reapply the things you previously stashed.