Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: multiline commit message on the command line?

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
like image 840
Martin Avatar asked Jan 24 '09 12:01

Martin


People also ask

How do I write a multiline commit message in terminal?

Another method of adding a multi-line Git commit message is using quotes with your message, though it depends on your shell's capacity. To do this, add single or double quotes before typing the message, keep pressing enter and writing the next line, and finally close the quote at end of the message.

What is the command to commit a message in Git?

To add a Git commit message to your commit, you will use the git commit command followed by the -m flag and then your message in quotes. Adding a Git commit message should look something like this: git commit -m “Add an anchor for the trial end sectionnn.”


7 Answers

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
like image 69
Aaron Maenpaa Avatar answered Oct 13 '22 02:10

Aaron Maenpaa


From Windows cmd, do this command for a multiline commit.

hg commit -l con

This allows you to enter a multiple line commit message straight from the command line. To end your message, hit Enter, and on a line by itself hit Ctrl + Z and Enter again.

Why? The -l option to hg commit says to read the commit message from a file, and con specifies that the file is actually the console.

like image 42
Cody Piersall Avatar answered Oct 13 '22 00:10

Cody Piersall


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.

like image 38
Jason S Avatar answered Oct 13 '22 00:10

Jason S


I know, there is already a solution for linux users, but I needed another solution for windows command line, so I was looking for it...

And I found one: https://www.mercurial-scm.org/pipermail/mercurial/2011-November/040855.html

hg commit -l filename.txt

I hope, it's useful for someone out there ,)

[EDIT] oO - it has already been added to the help

-l --logfile FILE read commit message from file

like image 31
kapsiR Avatar answered Oct 13 '22 02:10

kapsiR


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

hg commit -m "$(echo -e 'foo\nbar')"
like image 42
Leslie P. Polzer Avatar answered Oct 13 '22 02:10

Leslie P. Polzer


In bash (since version 2.0):

hg commit -m $'foo\nbar'

(I.e. put a dollar sign before an opening single quote to make it parse escape sequences (like \n) within the string — note that it doesn't work with double quotes.)

like image 45
Sasha Avatar answered Oct 13 '22 00:10

Sasha


For Windows with PowerShell:

 hg commit --message "foo`nbar"
like image 38
CodeFox Avatar answered Oct 13 '22 01:10

CodeFox