revision control with tortoisehg
Skip this Video
Download Presentation
Revision Control with TortoiseHg

Loading in 2 Seconds...

play fullscreen
1 / 98

Revision Control with TortoiseHg - PowerPoint PPT Presentation

  • Uploaded on

Revision Control with TortoiseHg. Team version. (Team use). CS2103 – Software Engineering. Prepared by: Steve Teo (past tutor) Contributors: Tong Huu Khiem (current tutor). Before we begin…. Red, bold text are important things. Notes clarify things and provides more in-depth knowledge.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Revision Control with TortoiseHg' - minty

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
revision control with tortoisehg

Revision Control with TortoiseHg

Team version

(Team use)

CS2103 – Software Engineering

Prepared by: Steve Teo (past tutor)

Contributors: Tong Huu Khiem (current tutor)

before we begin
Before we begin…

Red, bold text are important things.

Notesclarify things and provides more in-depth knowledge

These gray boxes have notes inside

These instructionsis tested with version 2.4.2 of TortoiseHg

Red box means instructions.Follow them.

Except the titles, of course 

moving on from individual use
Moving on from individual use…
  • Version control is important for an individual developer.
  • Regularrevision controlhelps a developer manage his/her code, increasing productivity.
  • The Mercurial Revision Control System offers the advantage of having a local repository
    • With a local repository, commits and other repository operations can be done offline at any time.
    • Developers, especially those who have used RCSs such as Subversion (which lacks the local repository feature), will find regular versioning with Mercurial a joy, not chore.
  • However, you have yet to fully utilize the capabilities of a Revision Control System if you’re using it alone.
to team use of a rcs
… to team use of a RCS
  • RCS is used to manage the codebase of software development projects (which consists of teams of developers) in the industry, making it crucialto learn how to use it properly now.
  • The Mercurial Revision Control System is fully capable of supporting team projects.
  • Adopting a RCS for team use requires the establishment of a workflow and making sure team members follow it.
  • In this first part, we shall learn a workflow to get a good grasp of it before proceeding with the practical itself.
  • Learn the Central Repository Model
    • Role of the team’s centralized repository
    • Basic team workflow
  • Putting everything into practice
    • Setup a Google Code Repository
    • Checkout a remote repository
    • Sync a local repository with a remote repo
    • Configure username for identity purpose
    • Push changesets
    • Pull-Update changesets
    • Merge changesets
    • Resolve merge conflict
  • Unleash Mercurial’s full power
the missing link
The missing link
  • Every team member will have their own local repository. However, there is no mechanism yet to share code changes with one another.

Team Leader’s Local Repo

Member A’s Local Repo

Team Leader

Member A

Member C’s Local Repo

Member B’s Local Repo

Member C

Member B

central repository model1
Central Repository Model
  • In the Central Repository Model, there is a central (remote) repository owned by the team
  • Team members download (‘pull’) and upload (‘push’) changes between their own local repositories and the central repository.
  • A team member’s local repository cannot sharechanges directly with other members’ local repositories.
  • Developers can choose to push their changes to the central repository only when they are confident of their changes.
  • Thus, it is not guaranteed that the central repository will always have the latest code.
  • However, it is expected to contain the latest stable code.
central repository model2
Central Repository Model

Team’s Central Repo

Leader’s Local Repo

Member A’s Local Repo

Team Leader

Member A

Member C’s Local Repo

Member B’s Local Repo

Member C

Member B

  • Update your changes from the local repo to a remote repo


Team’s Central Repo

Member A’s Local Repo

revision changeset
  • A revisionis the set of changes whenever a push is performed. Each revision is given a number. A revisionis also known as a changeset. In this tutorial, we will use both terms interchangeably.
  • A revision contains other important information such as the author of the changes and the summary of each change.
  • Each successful commit will result in a new revision.
  • Each revision will definitely have one or more revision for its parent except for the first revision, which will have zero.
  • Retrieve new changes from the remote repo to your local repo


Team’s Central Repo

Member A’s Local Repo

update merge
  • Pulling changes only retrieves changes from the remote repository into the local repository. However, the working copy is not updated in a Pull operation.
  • You need to update the working copy to the latest version by using the Updatecommand. If there are multiple heads (i.e. same file modified by multiple persons), you need to use the merge command instead.

Member A’s Local Repo

Member A’s Working Copy


pull update
  • There are a few ways of doing a pull and update in one shot.
  • In Step 3 of “Putting everything into practice”, we will show you how you can set up such behavior using TortoiseHg itself.
  • For the command line gurus, you can use the hg fetch command to do pull and update in one shot (need to enable the fetch extension first).
pulling and pushing diagram
Pulling and pushing (Diagram)

Member B’s Local Repo

Member B

Team’s CentralRepo

4. pulland merge

3. Tells him to pull

Member A’s Local Repo

Member A

2. pushchanges

1. makes some changes and commit

pulling pushing explanation
Pulling & pushing (explanation)
  • In the above model, Member A commits some changes and pushes them to the Central Repository.
  • Member A then informs the team to pull his changes off the Central Repository. Member B decides to do so and merges the changes from the Central Repository into his own repository.
  • If any other member wishes to have the latest stable code, all they have to do is to pull off the Central Repository.
setup a google code repository1
Setup a Google Code Repository
  • In this guide, we shall use the excellent open source hosting site Google Code as an example. However, note that your code will be available for checkout by anyone.
  • There are other Mercurial repository-hosting sites such as BitBucket at, which offers free private repositories as long as access to the repository is kept to 5 users.

Note for CS2103/T students: Your project tutor will set up the Google Code account for you. Instructions under step 1 are for your information only. But you should follow from Step 2 onwards.

setup a google code repository2
Setup a Google Code Repository

Sign up for a new project at

Choose Mercurial as your version control system

setup a google code repository3
Setup a Google Code Repository

Go to Sourcetab -> Checkout

Remember to note downthe repository URL

Take note of your repository URL

Access your password

setup a google code repository4
Setup a Google Code Repository

Rememberof your password, too

You need this password to push changeset to Google Code

You can access all the project you have here

setup a google code repository5
Setup a Google Code repository

Browse the code in your repository by going to Sourcetab-> Browse

Files will shows up as you commit code

setup a google code repository6
Setup a Google Code repository

View all the changes in your project by going to Sourcetab-> Browse

A commit graph will shows up as you commit code

setup a google code repository7
Setup a Google Code repository

Add your team members as Ownersunder the Administertab -> Sharing

Emails of your team members go here

setup a google code repository8
Setup a Google Code repository

Remember to create a Google group for your team and add it to the activity notification under Administertab-> Source

Add your team’s google group email here

clone a repository1
Clone a repository

If you alreadyhave an existing repository of the project on Google Code (set up by one of your team members), you can cloneit from the Google Code repository to your hard disk. Otherwise,skip to Step 3

Right-click on a new folder and select TortoiseHg - Clone

clone a repository2
Clone a repository

Cloningallows you to duplicate the entire repository, copying all the existing contents to the destination as well as the whole revision history.

Paste the Google Code repo URL here. This slide explains where to find the Google code repo URL.

sync a local repository with a remote repo1
Sync a local repository with a remote repo

If you have an existing local repository, you can also configure it to sync with the repo on Google Code

Click Synchronize

sync a local repository with a remote repo2
Sync a local repository with a remote repo

Add the Google Code repository URL as the default path

Choose https

Use “”

Use the relative URL


Use “default” for alias

sync a local repository with a remote repo3
Sync a local repository with a remote repo

You can also configure Post-Pull behaviorfor repositories

Select Post Pull

Update option will make TortoiseHg automatically update your repository whenever you pull some change

configure username for accountability1
Configure username for accountability

In a team setting, you need to establish an identityso that you and your teammates know what you guys committed

Select a repository and choose Repository Settings

configure username for accountability2
Configure username for accountability

Unser Commitgroup, enter the username & email that you want to associate your commits with

Use “name ” here

configure username for accountability3
Configure username for accountability

You can also set the username in the global settings. If there are no repository-specific settings specified, Mercurial will use the global settings.

This affects every repository on your computer

configure username for accountability4
Configure username for accountability

From now on, your name will show up in subsequent commits

This commit username can be different from your Google Code username

Commits now have the author which you have just specified

push changesets
Push changesets

After making some commits to our local repository, we are ready to push all of them into our Central Repository for the first time.

Right click on your local repo and choose Hg Workbench

push changesets1
Push changesets

In Hg Workbench, we will first previewthe commits that are to be pushed.

Click here to preview which changes will be going to the repo

Click Detect outgoing changes. This will compare the local and remote repository, finding changes to be pushed

push changesets2
Push changesets

TortoiseHg will find all the changes that need to be pushed

Click Push to upload these to Google Code

These are the changes that is going to be pushed

push changesets3
Push changesets

Then you will need to authenticate TortoiseHg to reach your Google code repository

Enter your Google code username

push changesets4
Push changesets

And your Google code password, as well. This is not your Google password. This slide explains where to get this password.

Enter your Google Code password

push changesets5
Push changesets

If the commits are pushed successfully, there will be no errors. You can look at the output logfor more info in any case.

Success 

push changesets6
Push changesets

You can also do a quick verification of the success of your commits by detecting changes for pushing again

This directly push changes, without checking. Not recommended for now

Click here

Your commit was pushed

push changesets7
Push changesets

Go to your Google code repository, check the Sourcetab-> Changes

You should see that your commits were pushed successfully here

push changesets8
Push changesets

If you find it a chore to enter your login details every time you push changes or pull from a private repository which you have pull access from, you can store your login detailsusing TortoiseHg.

Click “Synchronize” to open the sync panel at the bottom

Click on the lock to openthe security panel

Key in your Google account details

pull update changes
Pull & update changes

Let’s say Greg have pushed his code. Now his friend, Holly decides to pull the changes into her currently empty local repository.

Again, open Hg Workbench

pull update changes1
Pull & update changes

In Hg Workbench, you can check for new changes from repository

Check for changes from Google Code

pull update changes2
Pull & update changes

When new changes are detected, you can accept and download them

Click to download changes below

pull update changes3
Pull & update changes

The changes have been pulled into the local repository. However, we still need to update the working copy to the latest changes.

This means there are changes that is more up-to-date (2 and 3). You will need to update

pull update changes4
Pull & update changes

You can update in Hg Workbench or right-click on the repository and use the popup menu

Click Update to openthe update dialog

pull update changes5
Pull & update changes

Use the default option to update to the latest changes

pull update changes6
Pull & update changes

Once updated, everything is fine again. No more error message

pull update changes7
Pull & Update changes
  • Finding it so troublesome to pull and then update? You can configure TortoiseHg to update for you by simply configuring the Post-Pull behavioras listed in Step 3: Sync a local repository with a remote repo
  • Summary:
    • Pullingonly pulls the changesets into the local repository.
    • You still need to updatethe working copywith the new changesets.
    • Keep repeating this to yourself: Pull and Update
merge changesets1
Merge changesets
  • You may encounter this common scenarioGreg pushed his code to the repository. Then Holly & Rowley pulled and updated Greg’s code. Rowley then made some changes, committed and pushed them. Meanwhile, Holly also made her own changes and was about to push the code.
  • This can be summarized in the following timeline
merge changeset
Merge changeset

Team Repository (Google Code)



Commit new code

Pulled & Updated



Try to push

Pulled & Updated

Commit new code



merge changesets2
Merge changesets

In this situation, Rowley can’t push. He must merge his changes with Holly’s

This is how Google Code look like after Rowley has pushed his code

merge changesets3
Merge changesets

Here, Holly check her code and detected one that need to be pushed

merge changesets4
Merge changesets

When she push, however, there was an error. This is because she needs to pull Rowley’s code first

merge changesets5
Merge changesets

Holly proceeds to pull Rowley’s code, seeing one changeset

merge changesets6
Merge changesets

After Holly have pulled Rowley’s code, the repository look like this

Now, she need to merge her changes (4) with Rowley’s (5)

The newly pulled changeset

merge changesets7
Merge changesets

Holly first select Rowley’s change and proceed with the merge

Use Merge with local… to merge the new incoming changesets with yours

merge changesets8
Merge changesets

A summary of the upcoming merge is displayed on the 1st step of the merging process.

merge changesets9
Merge changesets

Mercurial proceeds to merge and the merge results are shown on the 2nd step of the merging process.

merge changesets10
Merge changesets

The process of Merging must be finalized with a commit to save the merge on the 3rd step of the merging process.

merge changesets11
Merge changesets

The merge is done. Holly will now need to push the finalized merge commit back to the repository on Google Code

The commit for the merge

merge changesets12
Merge changesets

The merge commit and Holly’s own commits earlier are marked for pushing

merge changesets13
Merge changesets

And then they’re pushed to the remote repository

merge changesets14
Merge changesets
  • Has this whole section been mind-boggling? Remember, the goal of merging is to combine changes between changesets. Once the merge is complete, it has to be committedand then pushedback to the remote repository.
  • Summary of merging steps :
    • Pull the incoming changesets from the remote repository
    • Merge the latest incoming changeset with the local working copy
    • Commit the merge into the local repository
    • Push the merge back to the remote repository
  • Find out more about Mercurial’s merging:
resolve merge conflict1
Resolve merge conflict
  • The merging scenario which was described in Step 7 is an example of a happy flow. There were no merge conflicts and this should be the case most of the time.
  • In some cases, a merge conflict can result when two people were working on the same file and decided to commit their changes. When Mercurial merges both of their work, it realizes it cannot do so automatically on its own and thus requires intervention from the one who initiates the merge.
  • Merge conflicts are settled by a user selecting which portion of the changed code should be in the finalized file.
  • Merge conflicts can be avoided in Software Projects through proper software engineering and individual ownership of classes. However, should such a conflict occur, Mercurial is capable of handling it.
resolve merge conflict2
Resolve merge conflict
  • Let’s look at a more specific example:Rowley and Holly both started with the same code. Rowley then edited one file, committed and pushed it. At the same time, Holly also edit that file, committed and was about to push it. This creates a situation where Holly need to merge her changeset and Rowley’s, as we have seen in the last section about merge
  • Normally, if Holly and Rowley change different files, say file A for Rowley and file B for Holly, TortoiseHg will automatically merge, using the newer version of file A from Rowley and a newer version of file B from Holly
  • However, since they both change one file, TortoiseHg can’t figure out whose version to use. This situation causes a merge conflict
merge changeset1
Merge changeset

One file, project.txt for example

Commit new code

Pulled & Updated


Create version A of project.txt


Try to push

Pulled & Updated

Commit new code

Create version B of project.txt



resolve merge conflict3
Resolve merge conflict

In this real example, Rowley and Holly started from Holly’s version of the code, where she add Stylizer.h and Stylizer.cpp

They both started from this revision

resolve merge conflict4
Resolve merge conflict
  • Both Rowley and Holly decides to edit these files in their own way

Added a function called Stylize

[Stylizer.h], add:

void Stylize(fstream one_file);

[Stylizer.cpp], add:

void Stylizer::Stylize(fstream one_file)




Added a function called Style_file

[Stylizer.h], add:

void Style_file(fstream one_file);

[Stylizer.cpp], add:

void Stylizer::Style_file (fstream one_file)


resolve merge conflict5
Resolve merge conflict

Holly has edited the file and pushed her changeset to Google Code

Holly’s new changeset

resolve merge conflict6
Resolve merge conflict

While pushing his commit, Rowley got an error

Then he proceeds to do a pull

resolve merge conflict7
Resolve merge conflict

After Rowley pulled, he saw that Holly have one changeset that he doesn’t

Now he need to merge his change with Holly’s

The changeset Rowley pulled

resolve merge conflict8
Resolve merge conflict

Again, this is done using the Merge with localoption

Use Merge with local… to merge the new incoming changesets with yours

resolve merge conflict9
Resolve merge conflict

A dialog box shows up, summarizing the upcoming merge

resolve merge conflict10
Resolve merge conflict

However, a conflict showed up while merging

Rowley now need to resolve this before continuing

Click here to resolve the merge conflict

resolve merge conflict11
Resolve merge conflict

The Resolve conflicts dialog shows up


Mercurial Resolve – Let Mercurial resolve it automatically (trivial)

Tool Resolve – Let the default merge tool resolve it

Take Local – Takes the version of the file in local working copy.

Take Other – Take the other version of the file which is not the local working copy.

Mark as Resolved – Marks the file as resolved

resolve merge conflict12
Resolve merge conflict

For example, if you use Tool Resolve, TortoiseHg will launch kidff3and you can resolve the conflict there

resolve merge conflict13
Resolve merge conflict

After all conflicts are resolved, close the dialog box and commit the merge, similar to Step 7: Merge changeset

resolve merge conflict14
Resolve merge conflict

And this is how it is in Google code repository

The conflicted merge

resolve merge conflict15
Resolve merge conflict
  • The example above was the resolution of a simple merge conflict.
  • Even though Jane and Steve edited the same file, their changes were on different lines. Mercurial or the default Diff program was smart enough to resolve it automatically on its own. Therefore, Steve did not need to choose which changes he wanted.
  • In other complex cases, you and your team mates could have edited the same section of code. In those cases, you have to use the Diff program to select which sections of code you want in the final merged code.
  • As mentioned in the beginning of this step, you can avoid most of those cases by maintaining individual ownership of files and proper software engineering.
centralized revision control system
Centralized Revision Control System
  • So far, you were introduced to the Central Repository Model.
  • The Central Repository Model is an adaptation of the Centralized model supported by a group of RCS called Centralized Revision Control Systems(CRCS for short), of which the most notable is Subversion (SVN for short).
  • In CRCS, there is a central repository hosted on a remote server but no local repositories. Developers synchronize changes directly to the central repository and a network connection is required for most repository operations.
centralized model
Centralized Model
  • Compare this with the Central Repository Model on Slide 9

Team Leader

Member A

Team’s Central Repo

Member C

Member B

distributed revision control system
Distributed Revision Control System
  • Mercurial belongs to a group of RCS known as Decentralized Revision Control Systems(DRCS), which includes Git.
  • DRCS uses the Decentralized Model: repositories are decentralized and repository configuration is flexible.Hence the workflow can vary differently from team to team.
  • In the general model, every team member has his/her own remote repository in addition to their own local repository. There is no such thing as the central repository.
pulling pushing in decentralized model
Pulling & Pushing in Decentralized Model

Member B’s Local Repo

Member B’s Hosted Repo

Member B

6. pushchanges

5. pulland merge

1. pulland merge

4. sends pullrequest

Member A’s Local Repo

Member A’s Hosted Repo

Member A

3. pushchanges

2. makes some changes and commit

pulling pushing in decentralized model1
Pulling & Pushing in Decentralized Model
  • You can see that Member A pulls the latest changes off Member B’s hosted repository and merges the changes with his local repository. Now that his local repository is updated, he then commits his own changes and pushes them to his hosted repository.
  • Member A then informs the team to pull his changes off his hosted repository. Member B decides to do so and merges the changes from Member A’s hosted repository into his own local repository.
  • Each of the members does not pull off from one another’s local repository. Instead, they pull off changes from one another’s hosted repository.
advantages of drcs in brief
Advantages of DRCS in brief
  • Presence of the local repository allows you to commit code and push the changes only when you are ready
  • No need for an Internet connection to commit changes or access your local repository, which means full benefits of version control anytime anywhere.
  • Flexible organization of repositories as workflow does not always have to be centralized
  • You can choose whether or not to pull from repositories and condemn your friend’s buggy code until it is fixed.
  • And many many more…