The Mercurial distributed version control system

Hg is not so scary

http://www.selenic.com/mercurial/

Author:Adam Lowry
Date:April 2, 2009

Basics

adam@rye:~/work/talks/hg$ hg init my_repo
adam@rye:~/work/talks/hg$ cd my_repo/
adam@rye:~/work/talks/hg/my_repo$ echo "This is a file." > foo.txt
adam@rye:~/work/talks/hg/my_repo$ hg status
? foo.txt
adam@rye:~/work/talks/hg/my_repo$ hg add foo.txt
adam@rye:~/work/talks/hg/my_repo$ hg commit -m "New foo file"
adam@rye:~/work/talks/hg/my_repo$ hg st
adam@rye:~/work/talks/hg/my_repo$

Using an Existing Repository

adam@rye:~/work/talks/hg$ hg clone my_repo my_repo_bugfix
updating working directory
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

Using an Existing Repository, cont'd

adam@rye:~/work/talks/hg/my_repo_bugfix$ echo "more" >> foo.txt
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg st
M foo.txt
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg ci -m "more foo"
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg outgoing
comparing with /Users/adam/work/talks/hg/my_repo
searching for changes
changeset:   1:d5b157a4648f
tag:         tip
user:        Adam Lowry <adam@therobots.org>
date:        Thu Apr 02 10:10:00 2009 -0700

Using an Existing Repository, cont'd 2

  • Push or pull, depending on workflow
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg push
pushing to /Users/adam/work/talks/hg/my_repo
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files

Getting Upstream Changes

adam@rye:~/work/talks/hg/my_repo$ echo "foo is the best" >> foo.txt
adam@rye:~/work/talks/hg/my_repo$ hg st
M foo.txt
adam@rye:~/work/talks/hg/my_repo$ hg ci -m "good foo"

Getting Upstream Changes, cont'd

adam@rye:~/work/talks/hg/my_repo_bugfix$ echo "bar" > bar.txt
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg add bar.txt
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg ci -m "new barfile"
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg in
comparing with /Users/adam/work/talks/hg/my_repo
searching for changes
changeset:   2:b45c36402618
tag:         tip
user:        Adam Lowry <adam@therobots.org>
date:        Thu Apr 02 10:20:39 2009 -0700
summary:     good foo

Getting Upstream Changes, cont'd 2

pull, update, merge (if necessary), commit (if merged)

adam@rye:~/work/talks/hg/my_repo_bugfix$ hg pull --update
pulling from /Users/adam/work/talks/hg/my_repo
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)

Getting Upstream Changes, cont'd 2

adam@rye:~/work/talks/hg/my_repo_bugfix$ hg merge
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg ci -m "Merged"

Working With Remote Repositories

  • ssh, http, sneakernet
adam@rye:~/work/talks/hg$ hg clone ssh://hg@bitbucket.org/jek/flatland
destination directory: flatland
requesting all changes
adding changesets
adding manifests
adding file changes
added 153 changesets with 556 changes to 132 files
updating working directory
82 files updated, 0 files merged, 0 files removed, 0 files unresolved

Identifying Authors

[ui]
username=Adam Lowry <adam@therobots.org>

Branchy Workflows

Every repository is a branch

  • Chad and Chris work on i18n
  • Chad commits initial work, then they split up
adam@rye:~/work/talks/hg/my_repo$ hg serve

Big Picture Branching

Every repository is still a branch, even stable and dev

adam@rye:~/work/talks/hg$ hg clone my_repo my_repo-1.0
updating working directory
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

Tagging releases

adam@rye:~/work/talks/hg/my_repo$ hg tag 1.0
adam@rye:~/work/talks/hg/my_repo$ hg heads
changeset:   3:d063f3399803
tag:         tip
user:        Adam Lowry <adam@therobots.org>
date:        Thu Apr 02 10:51:11 2009 -0700
summary:     Added tag 1.0 for changeset b45c36402618

Extensions

  • Fetch
  • Transplant
  • Shelve

FetchExtension

pull, update, merge in one go

adam@rye:~/work/talks/hg/my_repo$ hg fetch ../my_repo_bugfix/
pulling from ../my_repo_bugfix/
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 1 changes to 2 files (+1 heads)
updating to 5:9d99fecc9c25
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
merging with 3:d063f3399803
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
new changeset 6:841b61a58db0 merges remote changes with local

FetchExtension, cont'd

adam@rye:~/work/talks/hg/my_repo$ hg tip
changeset:   6:841b61a58db0
tag:         tip
parent:      5:9d99fecc9c25
parent:      3:d063f3399803
user:        Adam Lowry <adam@therobots.org>
date:        Thu Apr 02 10:52:16 2009 -0700
summary:     Automated merge with file:///Users/adam/work/talks/hg/my_repo_bugfix

TransplantExtension

Pick individual changesets from another repository

adam@rye:~/work/talks/hg/my_repo_bugfix$ hg transplant -s ../my_repo
searching for changes
changeset:   3:d063f3399803
user:        Adam Lowry <adam@therobots.org>
date:        Thu Apr 02 10:51:11 2009 -0700
summary:     Added tag 1.0 for changeset b45c36402618

apply changeset? [ynmpcq?]: y
applying d063f3399803
d063f3399803 transplanted to 58a1046e0603

ShelveExtension

Temporarily set aside uncommitted changes

adam@rye:~/work/talks/hg/my_repo_bugfix$ me changes" >> bar.txt
adam@rye:~/work/talks/hg/my_repo_bugfix$ hg shelve
diff --git a/bar.txt b/bar.txt
1 hunks, 1 lines changed
shelve changes to 'bar.txt'? [Ynsfdaq?]  Y
@@ -1,1 +1,2 @@
 bar
+some changes
shelve this change to 'bar.txt'? [Ynsfdaq?]  Y
adam@rye:~/work/talks/hg/my_repo_bugfix$ cat bar.txt
bar

ShelveExtension, cont'd

adam@rye:~/work/talks/hg/my_repo_bugfix$ hg unshelve
unshelve completed
adam@rye:~/work/talks/hg/my_repo_bugfix$ cat bar.txt
bar
some changes

Resources