Zach Burlingame
Programming, Computers, and Other Notes on Technology

HOWTO: Extract Directory from Mercurial Repo with Full History

Extract a directory out of an existing Mercurial repo into a new, top level repo with full revision history. For example, you have:
<Project A>/<sub project B>
and you want to make <sub project B> its own repo.

# File: HOWTOExtractDirectoryIntoStandaloneRepoMercurial.notes
# Auth: burly
# Date: 03/01/2011
# Refs: http://mercurial.selenic.com/wiki/ConvertExtension
#       http://www.jmedved.com/2010/09/extracting-part-of-mercurial-repository/
# Desc: Extract directory out of an existing Mercurial repo into
#       a new, top level repo with full revision history.
#       e.g. You have <Project A>/<sub project B> and 
#       you want to make <sub project B> it's own repo.

#Enable hg convert
vim ~/.hgrc

######## BEGIN COPY BELOW THIS LINE ###########
[extensions]
convert =
########## END COPY ABOVE THIS LINE ############

# Clone the repo you want to extract from
mkdir ~/tmp
cd ~/tmp
hg clone /path/to/yer/repo-to-clone

# Make a filemap of the items you want to keep. 
vim filemap.txt

########## BEGIN COPY BELOW THIS LINE #########
include WindowsPowerEvents
rename WindowsPowerEvents .
############ END COPY ABOVE THIS LINE ########

# Extract the desired folder with the convert extension
hg convert --filemap filemap.txt repo-to-clone new-repo-name

# (Optionally) Import this repo into the primary location you want it
cd /path/to/primary/repo/location
hg pull ~/tmp/new-repo-name
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

*