Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force mercurial to accept an empty commit

I'm trying to convert an SVN repo with hgsvn and I have some commits where SVN properties where modified, but since Mercurial doesn't use those, it sees this as an empty commit and aborts. Is there any way to force this hg commit to accept a commit that doesn't change anything?

I'm not familiar enough with the internals of hgsvn to hack it to skip empty commits.

like image 804
Asa Ayers Avatar asked Aug 24 '10 22:08

Asa Ayers


People also ask

How do I force an empty commit?

Git makes this process of pushing an empty commit super simple. It's like pushing a regular commit, except that you add the --allow-empty flag. You can see that the commit has been pushed to your branch without any changes after running the above commands.

How do I change commit message in Mercurial?

Since version 2.2, the commit command has a --amend option that will fold any changes into your working directory into the latest commit, and allow you to edit the commit message. hg commit --amend can in fact be used on any changeset that is a (topological) branch head, that is, one that has no child changesets.


4 Answers

You can skip this commit if you add a local svn.$REVNUM tag to the head revision (=the revision which also has the svn.($REVNUM-1) tag now). Then you can continue with hgpullsvn.

Say your import is at this state (last imported rev is 15800, the property-only rev is 15801):

$ hg log -l1
changeset:   1234:123456789abc
branch:      trunk
tag:         tip
tag:         svn.15800
parent:      1233:cba987654321
user:        Rudi <[email protected]>
date:        Tue Aug 24 11:42:23 2010 +0200
summary:     Foobar

$ svn info
Path: .
URL: svn+ssh://example.com/foobar/trunk
Repository Root: svn+ssh://example.com/foobar
Repository UUID: 26c7c274-8ed1-4e7f-bdc1-5c767a948b10
Revision: 15801
Node Kind: directory
Schedule: normal
Last Changed Author: rudi
Last Changed Rev: 15801
Last Changed Date: 2010-08-24 14:00:29 +0200 (Di, 24 Aug 2010)

Then you simply add the svn.15801 tag:

$ hg tag -l -r 123456789abc svn.15801

and contunie to import.

But make a backup before you try this.

like image 79
Rudi Avatar answered Nov 04 '22 17:11

Rudi


I think you can't do empty commit in mercurial. Here's a thread explaining why.

like image 38
in3xes Avatar answered Nov 04 '22 19:11

in3xes


When I've needed empty commits in p4 and hg before, I've simply used a file that was set aside to 'be' the empty commit. Just dump a random string of some sort (I usually use the time and date) into the throwaway file, and hg commit away....

like image 41
Sniggerfardimungus Avatar answered Nov 04 '22 19:11

Sniggerfardimungus


As per @vorrtex's comment on the original question, the simplest method to force an empty commit in Mercurial is as follows:

  1. Add a new file (say, Dummy.txt) and commit.
  2. hg forget Dummy.txt
  3. hg commit --amend

This will remove Dummy.txt from the previous commit, leaving it empty. (You can use e.g. TortoiseHg for step 1 but you'll need to use a command line tool for steps 2 and 3.)

I'm adding this as a new answer because when scanning this thread originally I missed the comment, and the existing answers don't create a truly empty commit.

like image 30
Neil T Avatar answered Nov 04 '22 19:11

Neil T