Mercurial Distributed Version Control


Published on

Learn about the Mercurial Distributed Version control system and some of the awesome features it has.

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

  • Mercurial Distributed Version Control

    1. 1. Mercurial Distributed Source Control Presented by David Stockton for Front Range PHP User Group April 28, 2010
    2. 2. “If debugging is the process of removing bugs, then programming must be the process of putting them in.” - Anonymous
    3. 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. 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. 5. I could go on, but...
    6. 6. I could go on, but... The bottom line is...
    7. 7. I could go on, but... The bottom line is... Source control is absolutely essential!
    8. 8. Questions? Questions about source control in general?
    9. 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. 10. Common/Popular Source Control Tools CVS SVN (Subversion) ClearCase Perforce Microsoft Visual SourceSafe Git Mercurial
    11. 11. Common/Popular Source Control Tools BitKeeper Telelogic Synergy Visual Studio Team System StarTeam RCS Tons of others...
    12. 12. Types of Source Control Client Server Model (CVS, SVN, etc) Distributed (Git, Mercurial)
    13. 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
    14. 14. Who uses Mercurial? Adium Audacious BitBucket Growl Linux HA LinuxTV
    15. 15. Who uses Mercurial? Mozilla Netbeans Mutt OpenOffice OpenJDK OpenSolaris
    16. 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. 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. 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. 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. 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. 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. 22. #1 Awesome Thing Branches are easy ... But they’re pretty easy in CVS and SVN too
    23. 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. 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. 25. #3 Awesome Thing No network? No problem Work from anywhere Collaborate with a colleague in the middle of nowhere
    26. 26. Installation Mercurial is cross platform with excellent support on Windows, Linux and Mac Download binary for Windows or Mac ... or apt-get install mercurial yum install mercurial ermerge mercurial pkg install SUNWmercurial
    27. 27. Create a new Repository
    28. 28. What’d that do?
    29. 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. 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
    31. 31. Adding and Committing
    32. 32. Look at the repository
    33. 33. Look at the repository
    34. 34. Make some more changes
    35. 35. Easy peasy...
    36. 36. Enter developer #2
    37. 37. Developer 2 Commits
    38. 38. What does that commit look like? Pretty much the same Why? Luke Skywalker has his own repository
    39. 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
    40. 40. What’d that do?
    41. 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. 42. How to see those changes? Use ‘hg up’ Update your own workspace
    43. 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. 44. A matter of timing...
    45. 45. Dave commits changes
    46. 46. Luke commits changes
    47. 47. But then... Don’t use -f to force... Don’t do it...
    48. 48. Let’s merge
    49. 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
    50. 50. Merge Check-in
    51. 51. And it now looks like...
    52. 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. 53. Merge conflict in the making
    54. 54. Now the fun part Luke uses the force and does a check in and push before Dave does a check-in
    55. 55. Here comes trouble... Dave tries to commit ... And it works ...
    56. 56. But... it created a new head
    57. 57. To get Luke’s changes...
    58. 58. Merge 2 heads into 1 All that junk is kdiff3 launching. I should fix that...
    59. 59. Merge in kdiff3 Notice that the eggs part was automatically resolved
    60. 60. Merge completed
    61. 61. Commit the merge
    62. 62. What’d that do?
    63. 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. 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. 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. 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. 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. 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. 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. 70. Holy crap... That wasn’t even all the commands Or all the coolness
    71. 71. As time permits... hg bisect demo hg copy demo hg rename demo hg mq - Patching, orthogonal mutable changesets
    72. 72. Other sweet awesomeness Hooks Attic ACL
    73. 73. Excellent Resources Quick and easy overview: - Joel Spolsky’s explanation of Mercurial Mercurial: The Definitive Guide Available online at Or buy from or O’Reilly Media
    74. 74. Questions?