mercurial basics
So I’m teaching a class this semester, Introduction to Programming for Non-Majors. One of my goals is to familiarize the students with version control, a method of tracking changes made by one or more people to a group of files. The specific version control system we are using is called “mercurial”. Mercurial is an open source project, written in the programming language Python. It can be accessed from the command line on the mac or on a linux box.
For windows, TortoiseHg is an application that contains its own version of mercurial, python, and some modifications to windows explorer. If you are running windows, you should install TortoiseHg and look at their documentation for instructions on how to accomplish the commands in the rest of this post. The concepts are the same, only the interface changes.
A mercurial *repository* can be viewed as two components: a special file that tracks or makes changes to a specific folder, and a bunch of commands that let you interact with that file. The special file has to be inside the folder it is tracking, which means if you copy the folder from one computer to another, you copy the entire repository.
However, this process has to be done correctly, which is where the concept of CLONING or PUSHING comes in. You use the command:
hg clone [what you want to clone] [where you want to put it]
To copy a repository, and the command
hg push
To update the original folder with your changes.
To make changes to the repository, you can use the commands ADD, REMOVE, and COMMIT.
If I create a new file in the repository, or copy a file into the repository, the special file doesn’t automatically know what to do with it. The command
hg add [file you want to add]
tells mercurial to start tracking that file and make note of any changes that are made.
The command
hg remove [file you want to remove]
tells mercurial to STOP tracking a file, and ignore any changes.
hg commit -m 'some commit message' -u 'someuser'
saves the changes you have made to the special mercurial file. It creates a new version of the repository, like a snaphot in time of what all the files that are being tracked look like at the time you commit.
So the basic order of events is:
Step 1: create an online repository
Step 2: CLONE it to your hard drive
Step 3: place or create text files in the folder you created when you
cloned the repository.
Step 4: ADD those files to your repository
Step 5: COMMIT those changes
Step 6: Repeat steps 3-6 as needed
Step 7: PUSH your changes.
Repeat steps 3-7 as needed.