Asa Ayers
Asa Ayers

Reputation: 4894

How can I insert or alter a mercurial revision

How can I alter r0 so it looks like I added .hgignore when I created my repository or insert a commit before my current r0?

I just converted a huge SVN repo using hgsvn to mercurial. It took several hours and had to go through about a dozen branches to get the whole thing. My problem now is that .hgignore isn't committed, so when I hgimportsvn a branch, the .hgignore doesn't seem to come with it. I would like to insert that file as part of r0 or insert it before that (and shift everything by 1). I've also tried committing it at the end of my Mercurial trunk checkout, but it seems hgimportsvn always clones (branches?) from the same Mercurial revision my SVN branch was created from so .hgignore is lost again.

Upvotes: 8

Views: 723

Answers (2)

Gintautas Miliauskas
Gintautas Miliauskas

Reputation: 7892

Maybe you could commit .hgignore and then rebase the commit to the beginning of history (see https://www.mercurial-scm.org/wiki/RebaseProject).

Upvotes: 0

Mark Tolonen
Mark Tolonen

Reputation: 178179

You probably need something like the ConvertExtension. Check out the --splicemap option.

To create a new history with a .hgignore file added as the first revision:

  1. Create a new repository whose only revision is the .hgignore commit.
  2. Create a splicemap file containing two 40-char hashes: rev 0 of your current database, and rev 0 of your new database.
  3. Run hg convert <current_db_dir> <new_db_dir> --splicemap splice_filename

This adds each revision in the current database to the new database. The splicemap specifies editing of parents, so if revision 0 of the current database gets its parent set to revision 0 of the new database.

Below is a Windows batch file that creates a 3-revision database and a 1-revision database with an .hgignore file in it, the splices them together. The result should be what you are looking for. If you have a large original database it could take a while, since the entire history of the source database is re-written to the destination database.

@echo off

@REM Create a 3-revision database
hg init current
cd current
echo >file1
hg add
hg ci -m file1
echo >file2
hg add
hg ci -m file2
echo >file3
hg add
hg ci -m file3

@REM Add the first revision to the splice map
hg log -r 0 --template "{node} " > ..\map

@REM Display the result
hg log
cd ..

@REM Create a 1-revision database
hg init ignore
cd ignore
echo glob:*.txt>.hgignore
hg add
hg ci -m ignore

@REM Specify this node as the parent of the other
@REM database's first revision in the splice map
hg log -r 0 --template "{node}\n" >> ..\map
hg log
cd ..

@REM Here's the resulting splice map
type map

@REM Make a copy to store the result
hg clone ignore result

@REM Add revisions from "current" to "result" honoring
@REM the splice map
hg convert current result --splicemap map

@REM Display the result
cd result
hg log

Upvotes: 5

Related Questions