Clone and Merge Using Mercurial

These are just simple notes for cloning an hg repo and merging them together after changes have been made in the clone or both repos.

Clone

Cd to the directory that contains the repo you want to clone. Type:

hg clone REPO_NAME CLONED_REPO_NAME

This clones the repo into the same directory as the original.

Or if you are using TortoiseHg, right click on the repo in the side panel that lists all repos and select clone.

Manual Merge

Make sure all changes are committed in each repo. Then cd into the first repo and type:

hg pull PATH_TO_CLONE
hg update
hg merge

Relative paths work. At this point if there are conflicts between the original and the clone, they will need to be resolved (more on that later). If there are no conflicts, type:

hg commit

It’s interesting to consider what a conflict is. If a file is altered in one repo and not another, then merge just takes the altered version and over-writes the original. In my case, I am often cloning a Django project. By cloning, I can make quick minor changes (bug fixes) to the original and do major changes in the clone. To do this, I usually need to alter the settings file in the clone to point to a cloned version of the database. Major changes often involve major changes to the db. When I merge, usually no changes will have been made to settings.py. Thus after merge, the db will be wrong.

Merge Using TortoiseHg

When it comes to resolving merge conflicts, I prefer a graphical interface. Here is how to merge using TortoiseHg (v2.2).

  1. ***MAKE SURE BOTH REPOS ARE COMMITTED***
  2. Select the original repo
  3. Click on the Sync Button Screenshot from 2015-02-01 13:59:46
  4. Select the cloned repo.
  5. Click the pull button Screenshot from 2015-02-01 14:06:08 to start the merge.
  6. Right click on the clone branch and select “Merge with Local”
  7. Click on the Resolve link to pull up the resolve GUI.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s