Thursday, April 29, 2010

HG Walkabout

Just prior to taking a three week vacation to Europe I splurged and purchased a Netbook (HP Mini 210-1032CL). I don't recommend doing this at the very last minute, but sometimes...

I have a copy of O'Reilly's Mercurial book and I spent time looking around for a digital copy of the book. I didn't find it on the 'net. I finally located it while I was sitting at the gate in SFO in the TortoiseHG docs directory *sweet*!

I discovered that it was quite easy to use the great 'hg help' command. I found out that first I need to remove the chaff from CVS (CVS artifacts.) I also was scratching my head for a bit trying to figure out how to ignore files that I did not want added to the repository.

Directly from the hg help init:

hg init [-e CMD] [--remotecmd CMD] [DEST]

create a new repository in the given directory

    Initialize a new repository in the given directory. If the given directory
    does not exist, it will be created.

    If no directory is given, the current directory is used.

    It is possible to specify an "ssh://" URL as the destination. See 'hg help
    urls' for more information.

Now that I had a repository built I knew that I needed to tell Mercurial what files were in it. I forged ahead and did a 'hg add' only to discover that I'd inadvertently added all of the CVS directories as well as the files that typically end up in our .cvsignore files. So that lead me to discover both 'hg remove' and 'hg forget', all three commands are described below:

hg add [OPTION]... [FILE]...

add the specified files on the next commit

    Schedule files to be version controlled and added to the repository.

    The files will be added to the repository at the next commit. To undo an
    add before that, see hg forget.

    If no names are given, add all files to the repository.

hg remove [OPTION]... FILE...

aliases: rm

remove the specified files on the next commit

    Schedule the indicated files for removal from the repository.

    This only removes files from the current branch, not from the entire
    project history. -A/--after can be used to remove only files that have
    already been deleted, -f/--force can be used to force deletion, and -Af
    can be used to remove files from the next revision without deleting them
    from the working directory.

hg forget [OPTION]... FILE...

forget the specified files on the next commit

    Mark the specified files so they will no longer be tracked after the next
    commit.

    This only removes files from the current branch, not from the entire
    project history, and it does not delete them from the working directory.

To undo a forget before the next commit, see hg add.
I think I've figured out that there are multiple ways to save yourself with Mercurial. I thought I had to do a 'hg remove' and a 'hg forget', but I believe that could have been avoided by supplying an option to the remove command - 'hg remove --force' which says remove (and delete) file even if added or modified.

Sidebar: I'm flying at 573mph ground speed at 35000 feet somewhere over Lake Michigan right now. Yes I know in the first paragraph I said that I was sitting in the San Francisco airport at the gate, but I was interrupted when I had to get on the plane, a lunch/dinner and subsequent knap. My clock says its just after midnight in London, I'm not ready to give into the sleep and change time zones just yet :)

Using e-TextEditor now and you get the Mercurial icons in the Project viewer. Nice!

snap-20100429-0029

No comments:

Post a Comment