views:

1340

answers:

3

How can I specify a multiline commit message for mercurial on the command line?

hg commit -m "* add foo\n* fix bar"

does not work. The log shows:

changeset:   13:f2c6526e5911
tag:         tip
date:        Fri Jan 23 23:22:36 2009 +0100
files:       foobar.cpp
description:
    * add foo\n*fix bar
+10  A: 

Mercurial: multiline commit message on the command line?

Hit enter.

$ hg commit -m "Did some work
> Now I'm done"

One of the things is that only the first line shows up in hg log:

$ hg log
changeset:   0:d2dc019450a2
tag:         tip
user:        Aaron Maenpaa <[email protected]>
date:        Sat Jan 24 07:46:23 2009 -0500
summary:     Did some work

... but if you fire up "hg view" you can see that the whole message is there.

Edited to add:

... but hg -v log shows the whole message:

$ hg -v log
changeset:   0:d2dc019450a2
tag:         tip
user:        Aaron Maenpaa <[email protected]>
date:        Sat Jan 24 07:46:23 2009 -0500
files:       work
description:
Did some work
Now I'm done
Aaron Maenpaa
Thanks, this has been bugging me a long time ;-)
Martin
The "Enter" behavior is dependant on UNIX-like shells. Is there a way to do it with Windows CMD?
Hosam Aly
@Hosam Other than installing cygwin (or mingwin) and using bash I can't think of anything.
Aaron Maenpaa
@Hosam Aly: Can you use \n or \r\n or \r? I'm not sure if the shellexpands it, but Mercurial might.
Lucas Jones
@person-b: The shell does not expand it AFAIK, and I don't have Mercurial to check it. But @Jason has a good answer below.
Hosam Aly
+3  A: 

If you're doing it interactively (vs. from a script), just do hg commit without the -m flag. I'm not sure what the behavior is on Linux or Mac, but on Windows it pops up Notepad with a file that you fill out and save for a multiline message.

Jason S
Is there some way to save and close notepad all in one keystroke? That's what annoys me about this approach.
Doug McClean
I think there's a way (via an .ini file) to tell Mercurial to call some other application rather than Notepad, then you just need to find your favorite editor.
Jason S
A: 

Here's another way that is more close to what you tried at first:

hg commit -m "$(echo -e 'foo\nbar')"
skypher