Perform an empty commit with mercurial
With with Mercurial queues extension, I can make an empty commit with some commit message like so:
hg qnew patch_name -m "message"
Is there a way to do this without Mercurial queues? I tried simply:
hg commit -m "message"
but hg just says “nothing changed” and doesn’t do the commit, and I don’t see any “force” option that would override that.
If you’re wondering about my motivation for doing this: we have testing infrastructure where you push to a special repository and it will trigger automated tests to run. You need to put a special string into the commit message of the tipmost commit that says which tests to run. Obviously, I don’t want this string in there when I push to the actual repository. Rather than amending the commit twice (once to add the special string, and a second time to remove it), I would find it cleaner to just add an empty commit, and then roll it back — and I can do this with mq, but I’d like to find a way to do it without mq.
2 Solutions collect form web for “Perform an empty commit with mercurial”
You can use
hg commit --amend to create empty commits.
Just create an arbitrary commit and backout the change. Afterwards fold both commits together.
touch tmp # create dummy file hg add tmp # add file and... hg commit -m "tmp" # ... commit hg rm tmp # remove the file again and ... hg commit --amend -m "empty commit" # ... commit
You can make commit that’s closing the branch:
hg commit --close-branch -m "message"
You can close branch once, but it can be reopened with another commit. Simplest way to reopen branch without changing files is to tag some revision. So you can use
hg commit --close-branch for empty commit and then
hg tag for reopening.
Actually you can create new empty commits with just
hg tag command. It has
-m parameter for setting a commit message. If you don’t really care about correctness of this tags, you can use just one tag name by calling
hg tag with
hg tag t1 -f -m "message"