a brain-dump-repository of ade jones

Create new Mercurial repository from a sub directory of an existing repository

2015-04-30 by Ade Jones

Use the hg convert command to make a new repository from a sub directory and retain the change history.

Create a filemap of the tracked files in the subdirectory to include and and rename the files in the new repo.

This is on OS X but should work on other *nix with awk/gawk/equivalent to assist creating the filemap.

UPDATE 2015-09-29: the code now works with a sub directory name that contains space characters.

# cd to the full repo directory
cd path/to/full_repo

# export tracked files in sub directory by creating a filemap
export SUBDIR=name_of_subdir
hg locate -I "$SUBDIR" | awk '{print "include \"" $1 "\"";}' > ../filemap.txt
echo "rename \"$SUBDIR\" ." >> ../filemap.txt

# create new repo using filemap
hg convert --filemap ../filemap.txt . ../new_repo_name

# cd to new repo and update to latest head revision, the update is required if you want to see your files
cd ../new_repo_name
hg update

Gist

Windows command line version, much the same but needs a temporary file:


rem cd to the full repo directory
cd path\to\full_repo

rem export tracked files in sub directory by creating a filemap using an intermediary temp file
set SUBDIR=name_of_subdir
hg locate -I "%SUBDIR%" > ..\filemap.tmp
for /f "tokens=*" %A in (..\filemap.tmp) do @echo include %A >> ..\filemap.txt
echo rename "%SUBDIR%" . >> ..\filemap.txt
del ..\filemap.tmp

rem create new repo using filemap
hg convert --filemap ..\filemap.txt . ..\new_repo_name

rem cd to new repo and update to latest head revision, the update is required if you want to see your files
cd ..\new_repo_name
hg update

Gist

Posted in: Uncategorized Tagged: hg, mercurial, version control
← Fix name resolution on Windows PPTP VPN after IOS8/ OS X 10.10 Yosemite update
Add ‘Open Folder as Sublime Project’ to Windows Explorer context menu →

Recent Posts

  • Reset root password on MySQL
  • Mount NTFS volume as Read/Write on OS X El Capitan 10.11 using osxfuse/ntfs-3g
  • Check a share is mounted on Linux
  • Mount NTFS volume as Read/Write on OS X Yosemite 10.10 using osxfuse/ntfs-3g
  • Add ‘Open Folder as Sublime Project’ to Windows Explorer context menu

Archives

  • June 2016
  • December 2015
  • November 2015
  • August 2015
  • April 2015
  • October 2014
  • July 2014
  • June 2014
  • March 2013
  • February 2013

Categories

  • Code
  • Debian
  • MySQL
  • OS X
  • Uncategorized

Tags

.local automysqlbackup Debian DHCP hg Hibernate IOS8 Kubuntu logging mavericks mercurial MTU MySQL NetworkManager NTFS ntfs-3g osxfuse PPTP python RRAS SFTP SSH sshfs sublime text super user Ubuntu version control VPN windows Windows Server Yosemite

About me

I program computers to do the bidding of humans; been doing this since the eighties. That makes me pretty old.

This blog receptacle thing is intended as a place to keep technical information nuggets that I find useful; kinda like Transactive memory so I can cheerfully forget until a future retrieval time.

That is all.

Copyright © 2026 a brain-dump-repository of ade jones.

Omega WordPress Theme by ThemeHall