New hg repo from subdir

It's a joy when tools just work.

I needed to create a new repository from a subdir of another repository while preserving history. Since I'm pretty new to mercurial and was not sure there was a clean way of doing this.

After a quick search and a couple of tests I found out that convert was the thing to use. (It works with a lot of other SCM tools too.)

  1. Init the new repo
  2. Create a filemap
  3. Run convert

The filemap is just a text file with files to include or exclude. In my case I need just to include the subdir I wanted. There was a small gottcha here since I once had renamed the subdir. I needed to include the previous name in the filemap to preserve the entire history.

                                                                         
$ hg convert --filemap filemap /path/to/src/repo /path/to/new/repo             

RSS 2.0