Wednesday, 29 August 2012

Renaming files in TortoiseHg

I've only been using Mercurial for a short while, and only using
TortoiseHg, so things are still a bit unclear for me. I know, I know,
I should be reading all the way through to get a
good grounding in Mercurial, but it seems to be okay so far.

I'm testing out Mercurial on a little project I have to restructure a
project to use Maven instead of Ant, so there's inevitably some moving
of directories required.

But how do you move a file in Mercurial?

This is the annoying thing, they never use that word "move". They call
it "rename". I get it, Mercurial only cares about files, but for the
sake of real-world users who still use the word "move", there could be
a bit more guidance on this, IMHO.

Anyway, how to move a directory in TortoiseHg? You go to the parent
directory using Explorer, then you right-click and select "Rename".
Then you will get a dialog box where you select the location you will
place it in. By default, it will show the existing name (ie,
"src/com") in both the Source and Destination text fields. Now for the
Destination field, click on the corresponding "Browse" button and
select the new location where you will place the directory.

IMPORTANT: Make sure the name of the directory is also in the
destination field, as the contents will be moved to whatever location
is specified in Destination.

There is a checkbox with "Copy source -> destination" - what is this for?

It turns out this is just a way for the Mercurial "copy" command being
included in the Rename dialog. It's a bit of a confusing hack, in my

It's annoying that this is not discussed in the docos I've seen for TortoiseHg.

Found out from here:

If you tick the checkbox, it means Mercurial will copy the files, and
not move them. You'll end up with two copies, which might not be what
you want to do.


This is not the best way to move files or directories around. The best
way is to just move them, and then go to the top of the directory,
then right-click TortoiseHg to "Guess Renames"

1 comment:

Unknown said...

Thanks, that was useful.

Didn't even know about the 'guess' menu option.