SlideShare a Scribd company logo
Mercurial
Distributed Source Control
Presented by David Stockton for
Front Range PHP User Group
April 28, 2010
“If debugging is the process
of removing bugs, then
programming must be the
process of putting them in.”
	 	 	 - Anonymous
Source Control in a Nutshell
 A great way to avoid catastrophic mistakes with your
 code
 Essential - If your code is more than a few lines long
 and you’re not using source control, you must not think
 very highly of your work.
 If you’re not using source control, start now. Even CVS
 is better than no source control. (Not sure about VSS
 though)
Source Control in a Nutshell
 If you are working with a team (read, one or more other
 people) source control is essential
 If you’re working by yourself and you’ve ever made a
 mistake, source control is essential
 If you ever wished you could undo something you just
 did, source control is essential
 If you need to maintain different versions of the same
 code, source control is essential.
I could go on, but...
I could go on, but...


 The bottom line is...
I could go on, but...


 The bottom line is...

 Source control is absolutely
 essential!
Questions?



Questions about source control in general?
Goals of Source Control

Keep your source code safe
Allow you to look at different versions of your code
Allow multiple developers to work simultaneously
Allow multiple “branches” of code to be worked on at
the same time
Common/Popular Source
Control Tools
CVS
SVN (Subversion)
ClearCase
Perforce
Microsoft Visual SourceSafe
Git
Mercurial
Common/Popular Source
Control Tools
BitKeeper
Telelogic Synergy
Visual Studio Team System
StarTeam
RCS
Tons of others...
Types of Source Control


Client Server Model (CVS, SVN, etc)
Distributed (Git, Mercurial)
Mercurial


 Distributed Version Control System
 Works the way you want it instead of forcing you to use
 it in a certain way
 Used by lots of big projects
Who uses Mercurial?
Adium
Audacious
BitBucket
Growl
Linux HA
LinuxTV
Who uses Mercurial?
Mozilla
Netbeans
Mutt
OpenOffice
OpenJDK
OpenSolaris
How does it work?


Probably not the way you’d think if you’ve used CVS or
SVN or other client server VCS
(Version Control System)
How it’s different
 No central server
   ... or at least not one that’s required
 Works on changesets, not file or repository versions
 Changesets allow merges (shudder) to be simple
   This is a good thing since you’ll be merging a lot
   Learn to not be afraid of the merge
What else?

Doing a checkout gives you a full copy of the repository
  Including all changes, etc
Lose a server?
  Just clone another copy of the repository
What can you do with it?

Pretty much anything
Clone a repository to try out some experimental code
  If it works, keep it
  If not, delete it, no harm done
    And no evidence of your failed attempt
What can you do with it?

Work on a plane (and still check in code)
Collaborate with a colleague in a coffee shop
Pick and choose what you want in your repository
Push, pull and clone from other repositories
Make your VCS work how
you do!
Work on the road
Work from home
Work from work
Work from a plane
Work from a train
Work in an automobile (if you’re not driving)
#1 Awesome Thing


Branches are easy
... But they’re pretty easy in CVS and SVN too
Branches
If you’re working on Feature A and I am working on
Feature B, we’ve essentially branched
Two or more people working on code based on the
same thing creates branches
Named branches
Unnamed branches
Branches by cloning
#2 Awesome Thing

Branches being easy is great, but only if...
Merges are super easy!
Most merges handled automatically
Merge conflicts can be handled by a tool of your choice
  I like kdiff3
#3 Awesome Thing


No network? No problem
Work from anywhere
Collaborate with a colleague in the middle of nowhere
Installation
 Mercurial is cross platform with excellent support on
 Windows, Linux and Mac
 http://mercurial.selenic.com/
 Download binary for Windows or Mac
 ... or
   apt-get install mercurial
   yum install mercurial
   ermerge mercurial
   pkg install SUNWmercurial
Create a new Repository
What’d that do?
You now have a working
repository
If you don’t do command line there are other ways
IDE Integration - Eclipse, NetBeans, IntelliJ, Emacs,
Vim, TextMate, Visual Studio
Windows integration with TortoiseHg
Build/Management tools with Hg support:
CruiseControl, JIRA, Trac, Maven, Redmine, Hudson,
ant, etc
Add some code

Use ‘hg add’ to tell Mercurial about the files you want it
to track
Use ‘hg commit’ to tell Mercurial to check in code
  hg ci
  hg com
Adding and Committing
Look at the repository
Look at the repository
Make some more changes
Easy peasy...
Enter developer #2
Developer 2 Commits
What does that commit look
like?
Pretty much the same
Why?
Luke Skywalker
has his own
repository
How can I get Luke’s
Change?
Use ‘hg push’ from Luke’s instance
Use ‘hg pull’ on my instance to Luke’s instance
What’d that do?
What does it do to me?
Where are the changes?
Pushes do not
affect the working
copy
Why?
Updating the workspace could make me lose my work
How to see those changes?


Use ‘hg up’
Update your own
workspace
Let’s mix it up


 Dave makes a change to cookie to specify flour
 amount
 Luke makes a change to cookie to add eggs
A matter of timing...
Dave commits changes
Luke commits changes
But then...



 Don’t use -f to force... Don’t do it...
Let’s merge
Quick recap

First check-in goes in
Second check-in based on same code needs merge
‘hg pull’ + ‘hg merge’ took a fraction of a second
Merge was correct
Luke now needs to commit the merge and push back
to Dave’s server
Merge Check-in
And it now looks like...
Still too easy...

 Let’s try a merge conflict...
 Dave needs more flour in the recipe
   Also, Dave hasn’t updated his workspace with the
   merge results
 Luke wants to use cake flour
Merge conflict in the making
Now the fun part
Luke uses the force and does a check in and push
before Dave does a check-in
Here comes trouble...
 Dave tries to commit




 ... And it works ...
But... it created a new head
To get Luke’s changes...
Merge 2 heads into 1
All that junk is kdiff3 launching. I should fix that...
Merge in kdiff3
 Notice that the eggs part was automatically resolved
Merge completed
Commit the merge
What’d that do?
Crazy branch/merges

The example to the right was done with
just 5 users but I was purposely trying
to make lots of weird branch merge
situations occur.
Command overview
hg clone - clone a repository
hg merge - merge changes together
hg add - tell Mercurial to start caring about some files
hg commit - commit a new changeset
hg push - send your changesets to another server
hg pull - retrieve changesets from another server
Command overview cont...
hg update - Update your local workspace with the stuff
from hg pull
hg annotate - show which changeset is responsible for
each line in a file
hg diff - show the differences between files in your
workspace and the committed file
hg export - dump the header and diffs for one or more
changesets
Command overview cont...

hg forget - Forget the specified files (remove from
repository, not from workspace) when you commit
hg log - show revision history
hg remove - delete file and remove from repository
when you commit
hg serve - simple http server to show the repository
(useful for coffee shop working)
hg addremove - add all new files, remove deleted files

hg backout - reverse effect of earlier changeset

hg bisect - search changesets (DEMO)

hg branch - set or show branch names

hg branches - list all branches

hg copy - mark file as copied for next commit (DEMO)

hg heads - show repository or branch heads
hg help - Where I’m getting this list of commands

hg identify - identify the working copy

hg incoming - show new changesets in source

hg init - create a new repository

hg outgoing - show changesets not in destination

hg parents - show parents of working directory or
revision
Command overview cont...
hg status - Show what’s going to happen when you
commit
hg summary - Summarize state of working directory

hg paths - show aliases for remote repositories

hg rename - rename a file (same as hg copy + hg
remove) (DEMO)

hg tag - tag a revision

hg tags - show tags in repository
Holy crap...


 That wasn’t even all the commands
 Or all the coolness
As time permits...

 hg bisect demo
 hg copy demo
 hg rename demo
 hg mq - Patching, orthogonal mutable changesets
Other sweet awesomeness


Hooks
Attic
ACL
Excellent Resources

Quick and easy overview:
http://hginit.com - Joel Spolsky’s explanation of
Mercurial
Mercurial: The Definitive Guide
Available online at http://hgbook.red-bean.com/read/
Or buy from Amazon.com or O’Reilly Media
Questions?

More Related Content

PPTX
Mercurial presentation
PPTX
Agile Training: Roles and Expectations
PDF
Scrum Master Training at UM DI | 22nd and 23rd of Feb 2017
PDF
Another Scrum Cheat Sheet (great one pager)
PPTX
epithelial tissue histology ppt.pptx
PPTX
BLOOD VESSELS HISTOLOGY REVIEW.pptx
PPT
Shell_Scripting.ppt
Mercurial presentation
Agile Training: Roles and Expectations
Scrum Master Training at UM DI | 22nd and 23rd of Feb 2017
Another Scrum Cheat Sheet (great one pager)
epithelial tissue histology ppt.pptx
BLOOD VESSELS HISTOLOGY REVIEW.pptx
Shell_Scripting.ppt

Viewers also liked (12)

PPT
Mercurial
PDF
Mercurial
PDF
Distributed Version Control (DVCS) With Mercurial
PPTX
Mercurial DVCS
PPTX
Mercurial: Beginners (v1)
PPTX
4. hg init – a mercurial tutorial by tortoise hg merging
PPTX
5. hg init – a mercurial tutorial by tortoise hg repository architecture
PDF
Mercurial intro
PDF
The Mercurial SCM
PDF
Mercurial DVCS presentation to DevJam 11/4/2009
PPTX
3. hg init – a mercurial tutorial by tortoies hg fixing goofs
PPTX
2. hg init – a mercurial tutorial by tortoies hg setting up for a team
Mercurial
Mercurial
Distributed Version Control (DVCS) With Mercurial
Mercurial DVCS
Mercurial: Beginners (v1)
4. hg init – a mercurial tutorial by tortoise hg merging
5. hg init – a mercurial tutorial by tortoise hg repository architecture
Mercurial intro
The Mercurial SCM
Mercurial DVCS presentation to DevJam 11/4/2009
3. hg init – a mercurial tutorial by tortoies hg fixing goofs
2. hg init – a mercurial tutorial by tortoies hg setting up for a team
Ad

Similar to Mercurial Distributed Version Control (20)

PDF
AtlasCamp 2010: What is DVCS and why it will change the way we work - Jens Sc...
PDF
Mercurial The Definitive Guide 1st Edition Bryan O'Sullivan
PDF
Mercurial The Definitive Guide 1st Edition Bryan O'Sullivan
PDF
Hg version control bioinformaticians
PDF
Introduction to mercurial
PDF
Making the switch to DVCS
PPT
How to start your open source project
PDF
Why Git Sucks and you'll use it anyways
PPT
Version Control ThinkVitamin
PPTX
Introduction to Git and Github
PPTX
Mercurial training
PPT
Introduction to git
PPTX
Mercurial
PDF
Introduction of Google Code and Mercurial
KEY
Version Control Lassosoft 2009 Lasso Developers Conference
PDF
Dvcs With Mercurial (No Notes)
PDF
GTALUG Short Talk On Mercurial
PDF
Git_tutorial.pdf
PDF
Git introduction
PDF
Getting Started with (Distributed) Version Control
AtlasCamp 2010: What is DVCS and why it will change the way we work - Jens Sc...
Mercurial The Definitive Guide 1st Edition Bryan O'Sullivan
Mercurial The Definitive Guide 1st Edition Bryan O'Sullivan
Hg version control bioinformaticians
Introduction to mercurial
Making the switch to DVCS
How to start your open source project
Why Git Sucks and you'll use it anyways
Version Control ThinkVitamin
Introduction to Git and Github
Mercurial training
Introduction to git
Mercurial
Introduction of Google Code and Mercurial
Version Control Lassosoft 2009 Lasso Developers Conference
Dvcs With Mercurial (No Notes)
GTALUG Short Talk On Mercurial
Git_tutorial.pdf
Git introduction
Getting Started with (Distributed) Version Control
Ad

More from David Stockton (19)

PDF
Phone calls and sms from php
PDF
The Art of Transduction
PDF
Using queues and offline processing to help speed up your application
PDF
Intermediate OOP in PHP
PDF
Building APIs with Apigilty and Zend Framework 2
PDF
API All the Things!
PDF
Intermediate OOP in PHP
PDF
Hacking sites for fun and profit
PDF
Beginning OOP in PHP
PDF
Common design patterns in php
PDF
Intermediate oop in php
PDF
Grokking regex
PDF
Hacking sites for fun and profit
PDF
Hacking sites for fun and profit
PDF
Increasing code quality with code reviews (poetry version)
PPT
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
PPTX
Regular expressions and php
PPTX
PHP 5 Magic Methods
PDF
FireBug And FirePHP
Phone calls and sms from php
The Art of Transduction
Using queues and offline processing to help speed up your application
Intermediate OOP in PHP
Building APIs with Apigilty and Zend Framework 2
API All the Things!
Intermediate OOP in PHP
Hacking sites for fun and profit
Beginning OOP in PHP
Common design patterns in php
Intermediate oop in php
Grokking regex
Hacking sites for fun and profit
Hacking sites for fun and profit
Increasing code quality with code reviews (poetry version)
Tame Your Build And Deployment Process With Hudson, PHPUnit, and SSH
Regular expressions and php
PHP 5 Magic Methods
FireBug And FirePHP

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Mercurial Distributed Version Control

  • 1. Mercurial Distributed Source Control Presented by David Stockton for Front Range PHP User Group April 28, 2010
  • 2. “If debugging is the process of removing bugs, then programming must be the process of putting them in.” - Anonymous
  • 3. Source Control in a Nutshell A great way to avoid catastrophic mistakes with your code Essential - If your code is more than a few lines long and you’re not using source control, you must not think very highly of your work. If you’re not using source control, start now. Even CVS is better than no source control. (Not sure about VSS though)
  • 4. Source Control in a Nutshell If you are working with a team (read, one or more other people) source control is essential If you’re working by yourself and you’ve ever made a mistake, source control is essential If you ever wished you could undo something you just did, source control is essential If you need to maintain different versions of the same code, source control is essential.
  • 5. I could go on, but...
  • 6. I could go on, but... The bottom line is...
  • 7. I could go on, but... The bottom line is... Source control is absolutely essential!
  • 8. Questions? Questions about source control in general?
  • 9. Goals of Source Control Keep your source code safe Allow you to look at different versions of your code Allow multiple developers to work simultaneously Allow multiple “branches” of code to be worked on at the same time
  • 10. Common/Popular Source Control Tools CVS SVN (Subversion) ClearCase Perforce Microsoft Visual SourceSafe Git Mercurial
  • 11. Common/Popular Source Control Tools BitKeeper Telelogic Synergy Visual Studio Team System StarTeam RCS Tons of others...
  • 12. Types of Source Control Client Server Model (CVS, SVN, etc) Distributed (Git, Mercurial)
  • 13. Mercurial Distributed Version Control System Works the way you want it instead of forcing you to use it in a certain way Used by lots of big projects
  • 16. How does it work? Probably not the way you’d think if you’ve used CVS or SVN or other client server VCS (Version Control System)
  • 17. How it’s different No central server ... or at least not one that’s required Works on changesets, not file or repository versions Changesets allow merges (shudder) to be simple This is a good thing since you’ll be merging a lot Learn to not be afraid of the merge
  • 18. What else? Doing a checkout gives you a full copy of the repository Including all changes, etc Lose a server? Just clone another copy of the repository
  • 19. What can you do with it? Pretty much anything Clone a repository to try out some experimental code If it works, keep it If not, delete it, no harm done And no evidence of your failed attempt
  • 20. What can you do with it? Work on a plane (and still check in code) Collaborate with a colleague in a coffee shop Pick and choose what you want in your repository Push, pull and clone from other repositories
  • 21. Make your VCS work how you do! Work on the road Work from home Work from work Work from a plane Work from a train Work in an automobile (if you’re not driving)
  • 22. #1 Awesome Thing Branches are easy ... But they’re pretty easy in CVS and SVN too
  • 23. Branches If you’re working on Feature A and I am working on Feature B, we’ve essentially branched Two or more people working on code based on the same thing creates branches Named branches Unnamed branches Branches by cloning
  • 24. #2 Awesome Thing Branches being easy is great, but only if... Merges are super easy! Most merges handled automatically Merge conflicts can be handled by a tool of your choice I like kdiff3
  • 25. #3 Awesome Thing No network? No problem Work from anywhere Collaborate with a colleague in the middle of nowhere
  • 26. Installation Mercurial is cross platform with excellent support on Windows, Linux and Mac http://mercurial.selenic.com/ Download binary for Windows or Mac ... or apt-get install mercurial yum install mercurial ermerge mercurial pkg install SUNWmercurial
  • 27. Create a new Repository
  • 29. You now have a working repository If you don’t do command line there are other ways IDE Integration - Eclipse, NetBeans, IntelliJ, Emacs, Vim, TextMate, Visual Studio Windows integration with TortoiseHg Build/Management tools with Hg support: CruiseControl, JIRA, Trac, Maven, Redmine, Hudson, ant, etc
  • 30. Add some code Use ‘hg add’ to tell Mercurial about the files you want it to track Use ‘hg commit’ to tell Mercurial to check in code hg ci hg com
  • 32. Look at the repository
  • 33. Look at the repository
  • 34. Make some more changes
  • 38. What does that commit look like? Pretty much the same Why? Luke Skywalker has his own repository
  • 39. How can I get Luke’s Change? Use ‘hg push’ from Luke’s instance Use ‘hg pull’ on my instance to Luke’s instance
  • 41. What does it do to me? Where are the changes? Pushes do not affect the working copy Why? Updating the workspace could make me lose my work
  • 42. How to see those changes? Use ‘hg up’ Update your own workspace
  • 43. Let’s mix it up Dave makes a change to cookie to specify flour amount Luke makes a change to cookie to add eggs
  • 44. A matter of timing...
  • 47. But then... Don’t use -f to force... Don’t do it...
  • 49. Quick recap First check-in goes in Second check-in based on same code needs merge ‘hg pull’ + ‘hg merge’ took a fraction of a second Merge was correct Luke now needs to commit the merge and push back to Dave’s server
  • 51. And it now looks like...
  • 52. Still too easy... Let’s try a merge conflict... Dave needs more flour in the recipe Also, Dave hasn’t updated his workspace with the merge results Luke wants to use cake flour
  • 53. Merge conflict in the making
  • 54. Now the fun part Luke uses the force and does a check in and push before Dave does a check-in
  • 55. Here comes trouble... Dave tries to commit ... And it works ...
  • 56. But... it created a new head
  • 57. To get Luke’s changes...
  • 58. Merge 2 heads into 1 All that junk is kdiff3 launching. I should fix that...
  • 59. Merge in kdiff3 Notice that the eggs part was automatically resolved
  • 63. Crazy branch/merges The example to the right was done with just 5 users but I was purposely trying to make lots of weird branch merge situations occur.
  • 64. Command overview hg clone - clone a repository hg merge - merge changes together hg add - tell Mercurial to start caring about some files hg commit - commit a new changeset hg push - send your changesets to another server hg pull - retrieve changesets from another server
  • 65. Command overview cont... hg update - Update your local workspace with the stuff from hg pull hg annotate - show which changeset is responsible for each line in a file hg diff - show the differences between files in your workspace and the committed file hg export - dump the header and diffs for one or more changesets
  • 66. Command overview cont... hg forget - Forget the specified files (remove from repository, not from workspace) when you commit hg log - show revision history hg remove - delete file and remove from repository when you commit hg serve - simple http server to show the repository (useful for coffee shop working)
  • 67. hg addremove - add all new files, remove deleted files hg backout - reverse effect of earlier changeset hg bisect - search changesets (DEMO) hg branch - set or show branch names hg branches - list all branches hg copy - mark file as copied for next commit (DEMO) hg heads - show repository or branch heads
  • 68. hg help - Where I’m getting this list of commands hg identify - identify the working copy hg incoming - show new changesets in source hg init - create a new repository hg outgoing - show changesets not in destination hg parents - show parents of working directory or revision
  • 69. Command overview cont... hg status - Show what’s going to happen when you commit hg summary - Summarize state of working directory hg paths - show aliases for remote repositories hg rename - rename a file (same as hg copy + hg remove) (DEMO) hg tag - tag a revision hg tags - show tags in repository
  • 70. Holy crap... That wasn’t even all the commands Or all the coolness
  • 71. As time permits... hg bisect demo hg copy demo hg rename demo hg mq - Patching, orthogonal mutable changesets
  • 73. Excellent Resources Quick and easy overview: http://hginit.com - Joel Spolsky’s explanation of Mercurial Mercurial: The Definitive Guide Available online at http://hgbook.red-bean.com/read/ Or buy from Amazon.com or O’Reilly Media