Does Mercurial support empty commit messages? - mercurial

Is there a way to configure Mercurial to allow for empty commit messages? If you try hg commit through the CLI without entering a commit message, the commit is canceled with: abort: empty commit message.
Now, I know that committing without a message is usually considered bad form, but does Mercurial allow it at all?

You can use just a space, but I'd really discourage it:
hg commit -m " "

If the problem is that you don't want to enter the -m "blah" part you can always set up an alias. e.g. in hgrc
[alias]
qcommit = commit -m "quick commit - no message"
If you don't like qcommit then you can alias to commit instead i.e.
[alias]
commit = commit -m "quick commit - no message"
this won't help you with TortoiseHG however which presumebly validates its entry fields before passing data to mercurial iteslf

Related

hg merge says outstanding uncommitted changes; hg commit says nothing changed -- how to exit the loop?

The problem here is that hg' workflow apparently leads in a circle:
hg pull, get another head
hg merge, get warned of outstanding
uncommitted changes
hg commit -m "pre merge commit", get message
saying nothing changed
go to 2 hg status, see output like the
following:
! #foo.py#
? junk.out
? junk2.out
If foo.py is in your list of .hg-ignore'd files try specifying it explicity on the command line when you commit.
e.g.
hg commit -m "commit message" ./#foo.py
edit: looking more closely at your error: the file has been deleted (! in the status list), but hg hasn't tracked the deletion. You need to tell hg about the deletion using:
hg rm -A ./foo.py
The -A / --after means record the removal after it actually occured

How do I edit an incorrect commit message in TortoiseHG Mercurial?

I mistakenly did a TortoiseHG commit while trying to do a new line, and wrote the totally wrong thing in the commit message. How can I change the commit message here ?
I have not yet pushed the commit.
Select "Amend current revision" from dropdown menu of commit button (marked on screenshot). Button title will become "Amend". Enter new commit message and click amend button.
Histedit extension allow you to edit commit message
You can perform next commit (change nothing) with --amend option and corrected commit message
hg add
adding file.txt
hg commit -m "Init"
hg commit -m "Initial commit" --amend
saved backup bundle to 719f9ea026f3-amend-backup.hg
hg log
changeset: 0:355197b0c857
...
summary: Initial commit

Empty commit with Mercurial

Is it possible to do a commit without any changes in the current repository with Mercurial, like git's --allow-empty?
Trick I read somewhere:
touch tmp
hg add tmp
hg commit -m "tmp"
hg rm tmp
hg commit --amend -m "Real commit message"
Unfortunately it doesn't survive rebasing (and maybe other operations).
The answer from #Thomas above is correct but doesn't fully explain how to modify the file content of a commit.
A simple method to use this feature to force an commit empty is as follows:
Add a new file (say, Dummy.txt) and commit.
hg forget Dummy.txt
hg commit --amend
This will remove Dummy.txt from the previous commit, leaving it empty.
With amend you can change the user, date, commit message and files content:
hg commit -m"new message" -d"$(date --rfc-2822)" -u"new user" --amend
These are probably all the reasons why you would want to commit an empty changeset.

hg commit opens an editor

when I run hg commit, vim editor is opened and shows
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
and shows some paths. What does that mean? what is the next step?
You can enter any information about your commit there. The message you enter will be shown in commit history hg log. You should briefly describe the changes made in your commits, because documented history is easier to track.
The next step is to save the temporary file in the editor to finalize the commit: :wq.
To avoid spawning an editor, you can enter the commit message directly on the command line using the -m option: hg commit -m "This is a commit message".
hg commit -m"Your message" -uNAME
NAME replaced with your username or similar.

How to avoid accidentally 'hg push' instead of 'hg qpush'?

For those of you that use Mercurial with the MQ extension:
This is the second time I accidentally submit changes to the central repository (hg push) instead of applying a patch to my working directory (hg qpush).
I think this is very unfortunate, because it is a very simple error to make and has very severe consequences (the least having to do a hg backout and an extra hg push for each submitted change in order to generate a new commit that "undoes" the las one to the central repository, but the history becomes convoluted and unpleasant.
My goal is to configure some alias or something in my environment in orden to make hg push harder to do by accident.
Do you have any suggestions? I was thinking something like:
[alias]
push= <-- how to NOP the push command??
pushtoserver=push
As this is a completely subjective question, this goes as community wiki.
thanks!
some vague ideas:
you could remove the default push location from your repo
you could write a "did you mean qpush? yes, no" pre-push hook
This hook (bash command line) asks for confirmation before pushing changes to the remote (tested with mercurial 1.4):
[hooks]
preoutgoing.confirm = read -p 'Are you sure you want to push to remote? (y/n): '; echo $REPLY | grep -q 'y'
you could alias push to qpush and alias pushtoserver to push (i think this works but can't try it now)
Put the following in your .hgrc:
[alias]
pushtoserver = push
push = 'Did you mean qpush or pushtoserver?'
Works like this:
$ hg push
alias 'push' resolves to unknown command 'Did you mean qpush or pushtoserver?'
$ hg pushtoserver
abort: repository default-push not found!
See also the alias section of the hgrc manpage.