A small tutorial on using Mercurial as a website repository.
This is a small tutorial on how to use mercurial 1.8.4. as a version control system. If you need information on what a version control system is: check out this link: Version Control.
A few things to note:
- This blog covers a Mercurial Repository I set up in a previous post: Installing Mercurial 1.8.4 on IIS 7.5 as a Repository website.
- Mercurial website repository = “source” repository.
- Repository located on home computer = “home” repository.
Configuring your repository:
- Make sure to be in the correct directory before you do any commands in mercurial, you may end up making changes you will regret later!
- My Repository (home repository) is located in “D:\Repositories”.
- It’s called “Repo_1”, located at “D:\Repositories\Repo_1”.
- At some point we might want to make changes to “Repo_1”. We can pull “Repo_1” from the Mercurial website Repository. “A pull propagates changesets from a “remote” repository (the source) into a local repository (the destination)” (Mercurial Wiki). When one pulls from the “source” repository, only changes that are not in the “home” repository will be added. Hg pulls all the changes, but doesn’t automatically update your working directory with the changes. The changes pulled area called ‘changesets’, and can include files, branches, heads, etc.
- Note: If you want to pull you must first have a repository named/initialized in your repository folders.
- Notice that if the repository is named correctly and not initialized the command “hg pull” will not work. The repository must be named and initialized for “hg pull” to work.
- The commands for “hg init” are below. (hg init initializes the repository)
- The commands for “hg pull” are below
hg pull https://mercurial.<your domain>/hg/repo_1
enter username: <your username>
enter password: <your password>
- If everything went correctly your home repository will have changesets added to it from the source repository.
- Keep the command prompt open, we will be using this for “hg update”.
- Now that we have pulled the changesets of Repo_1 off of the source repository, it is now possible to retrieve the files and folders off of the source repository. We can do this by using the command “Hg update”.
- My home repository for Repo_1 has no files contained inside of it.
- The source repository has three files on it right now, that I want on the home repository.
- My source repository has three files called “Repo_1_text.txt”, “Repo_update_text.txt” and “Other_New_Text.txt”. My goal is to have these files added to my home repository “Repo_1”.
- You always want to “hg pull” before we can do an “hg update”. That way, you have the most current repo information. You should still have the command prompt open from the last step. In the command prompt type in the following command.
- Simple! If everything worked out correctly, the three files from the source repository will be inside your home repository.
- Now let’s say we added a couple files to our home repository. These files are called “fox.txt” and “zebra.txt”. We have our current home repository how we like it, now we want to update the source repository to reflect the changes we’ve made. We can do this by “pushing” our changesets to the source repository.
- Couple updates, we must run “hg add” to add the “zebra.txt” and “fox.txt” files to our repository. Then we must run “hg commit“. It’s necessary to “commit” before each “push”.
- Here is my home repository before the hg push.
- Commands for push
hg commit -m "message" --user "username"
hg push https://mercurial.<yourDomain>/hg/repo_1
- This is what the source repository looks like after the push.