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.
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
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)
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
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
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
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
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
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