GTALUG Short Talk On Mercurial

46
What is Revision Control

description

I gave a short talk on Mercurial at GTALUG on 8th December, 2009.

Transcript of GTALUG Short Talk On Mercurial

Page 1: GTALUG Short Talk On Mercurial

What is Revision Control

Page 2: GTALUG Short Talk On Mercurial

• Allows multiple people to collaborate on a file.

Page 3: GTALUG Short Talk On Mercurial

AppleOrangesCherriesMilkApple Pear ChineseNoodlesPomegranateStrawberriesBananas

Page 4: GTALUG Short Talk On Mercurial

$ rc add 2009-12-11.txt$ rc commit -m 'Added the Grocery List for Friday 11 Dec, 2009.'

Page 5: GTALUG Short Talk On Mercurial

$ rc logreversion: 1author: Myles Braithwaitesummary: Added the Grocery List for Friday 11 Dec, 2009.

Page 6: GTALUG Short Talk On Mercurial

AppleOrangesCherriesMilkChinese White Pear Apple Pear ChineseNoodlesPomegranateStrawberriesBananas

Page 7: GTALUG Short Talk On Mercurial

$ rc statusModified: 2009-12-11.txt$ rc commit -m "It's called a Chinese White Pear not a Apple Pear Chinese Fruit"

Page 8: GTALUG Short Talk On Mercurial

$ rc diff -r 1diff -r 1 2009-12-11.txt--- a/2009-12-11.txt Thu Dec 03 15:45:38+++ b/2009-12-11.txt Thu Dec 03 15:51:39@@ -2,7 +2,7 @@ Oranges Cherries Milk-Apple Pear Chinese Fruit+Chinese White Pear Noodles Pomegranate Strawberries

Page 9: GTALUG Short Talk On Mercurial

$ rc logreversion: 1author: Myles Braithwaitesummary: Added the Grocery List for Friday 11 Dec, 2009.

reversion: 2author: Other Personsummary: It's called a Chinese White Pear not a Apple Pear Chinese Fruit

Page 10: GTALUG Short Talk On Mercurial

• Attempt to merge changes between two commits.

Page 11: GTALUG Short Talk On Mercurial

AppleOrangesCherriesMilkChinese White PearNoodlesPomegranateStrawberriesBananasTea

Page 12: GTALUG Short Talk On Mercurial

$ rc commit -m 'Added tea to the list'

Page 13: GTALUG Short Talk On Mercurial

Apple @doneOranges @doneCherries @doneMilkChinese White PearNoodlesPomegranateStrawberriesBananas

Page 14: GTALUG Short Talk On Mercurial

$ rc commit -m 'Went to the Grocery store and picked up Apples, Oranges, and Cherries.'

The Repository is Out of Sync. Please merge the new changes.

Page 15: GTALUG Short Talk On Mercurial

$ rc mergeMerge was successful.$ rc commit -m 'Merging changes'

Page 16: GTALUG Short Talk On Mercurial

StrawberriesBananas<<< HEADTea (Chai)>>>><<<< 6Tea (Green)>>>>

Page 18: GTALUG Short Talk On Mercurial

History

• Matt Machall

• Originally developed for the Linux Kernel.

• For some reason Torvalds’ picked Git?

Page 19: GTALUG Short Talk On Mercurial

Quick Facts

• Implemented in the awesome Python programming language.

• But includes a binary diff written in C.

Page 20: GTALUG Short Talk On Mercurial

• Originally written to run on Linux.

• But it has been successfully ported to run natively on Mac OS X, Windows, and other Unix-like systems.

Page 21: GTALUG Short Talk On Mercurial

• Python (http://hg.python.org)

• Mozilla (http://hg.mozilla.org)

• OpenSolaris

• OpenJDK (http://hg.openjdk.java.net)

• OpenOffice.org

• More here: http://j.mp/ProjectUsingHg

Page 22: GTALUG Short Talk On Mercurial

Installation (Linux)# Debian or Ubuntu$ aptitude install mercurial

# Fedora$ yum install mercurial

# Gentoo$ emerge mercurial

# OpenSolaris$ pkg install SUNWmercurial

Page 23: GTALUG Short Talk On Mercurial

Installation (Windows)

• Download and install the official exe.

• Download TortoiseHg (http://tortoisehg.org)

• Integrates Mercurial directly into explorer.

Page 24: GTALUG Short Talk On Mercurial

Installation (Mac OS X)

• Install the DMG file.

Page 25: GTALUG Short Talk On Mercurial

Installation (PyPi)

$ easy_install mercurial

$ pip install mercurial

Page 26: GTALUG Short Talk On Mercurial

Installation from Source

$ wget http://mercurial.selenic.com/release/mercurial-1.4.1.tar.gz$ tar -xzf mercurial-1.4.1.tar.gz$ cd mercurial-1.4.1$ python setup.py build$ sudo python setup.py install$ hg --versionMercurial Distributed SCM (version 1.4.1)

Page 27: GTALUG Short Talk On Mercurial

$ $EDITOR ~/.hgrc

[ui]username = Myles Braithwaite <[email protected]>

Page 28: GTALUG Short Talk On Mercurial

$ export P_DIR=~/GroceryList$ $ # Create an empty repository on your$ # local machine.$ mkdir $P_DIR; cd $P_DIR$ hg init$$ # Clone a remote repository.$ hg clone ssh://hg.mb/grocery_list $P_DIRdestination directory: /home/m/GroveryList...3 files updated, 0 files merged, 0 files removed, 0 files unresolved

Page 29: GTALUG Short Talk On Mercurial

$ echo 'Apple' > cat 2009-12-08.txt$ hg status? 2009-12-08.txt$ hg add 2009-12-08.txt$ hg statusA 2009-12-08.txt$ hg commit -m 'Added the grocery list for 9th Dec. 2009.'

Page 30: GTALUG Short Talk On Mercurial

$ hg statusM 2009-12-08.txt$ hg diffdiff -r 012549b5c017 2009-12-08.txt--- a/2009-12-08.txt 19:42:25+++ b/2009-12-08.txt 19:44:46@@ -1,1 +1,2 @@ Apples+Pizza$ hg commit -m 'I am hungry for some Pizza.'

Page 31: GTALUG Short Talk On Mercurial

$ hg log -l 2changeset: 14:848072d17be0tag: tipuser: Myles Braithwaitedate: 19:49:10summary: I am hungry for some Pizza

changeset: 13:012549b5c017user: Myles Braithwaitedate: 19:42:25summary: Added the grocery list for 9th Dec. 2009.

Page 32: GTALUG Short Talk On Mercurial

$ hg annotate 2009-12-08.txt 13: Apples14: Pizza15: Nuts16: Hot Chocolate Mix

Page 33: GTALUG Short Talk On Mercurial

$ hg tagstip 16:54c53457b1ac2009-12-04 9:d1361977c248$ hg tag 2009-12-08$ hg tagstip 17:21598a08291c2009-12-08 16:54c53457b1ac2009-12-04 9:d1361977c248

Page 34: GTALUG Short Talk On Mercurial

$ cat .hgtags d1361977c2... 2009-12-0454c53457b1... 2009-12-08

Page 35: GTALUG Short Talk On Mercurial

# If we cloned the repository.$ hg push

$ hg push ssh://hg.mb/grocery_list

Page 36: GTALUG Short Talk On Mercurial

$ hg pull ssh://hg.mb/grocery_listpulling from ssh://hg.mb/grocery_listsearching for changes...(run 'hg update' to get a working copy)$ hg update1 files updated, 0 files merged, 0 files removed, 0 files unresolved

Page 37: GTALUG Short Talk On Mercurial

$ hg log -l 2changeset: 20:6dfef8e8a348tag: tipuser: Other Personsummary: Remove some things fromthe list that were already entered on Friday' list.

changeset: 19:1564f5195566date: 16:30:18summary: Added a shopping list for Sat. 12 Dec. 2009

Page 38: GTALUG Short Talk On Mercurial

$ hg diff -r 19diff -r 1564f5195566 2009-12-12.odtBinary file 2009-12-12.odt has changed

Page 39: GTALUG Short Talk On Mercurial

$ # Using an extension we can call an$ # external program to run the diff.$ hg extdiff -p oodiff -r 19--- GroceryList.1565f5195566/2009-12-12.odt+++ GroveryList/2009-12-12.odt@@ -1,12 +1,4 @@

- Oranges- - Apples-- Bananas-- Cereal- Cherios

Beer

Page 40: GTALUG Short Talk On Mercurial

$ # To enable external diff's extension.$ $EDITOR .hg/hgrc[extensions]extdiff =

Page 41: GTALUG Short Talk On Mercurial

$ hg serve -n "Shopping List"

Page 42: GTALUG Short Talk On Mercurial
Page 43: GTALUG Short Talk On Mercurial
Page 44: GTALUG Short Talk On Mercurial

.hgignore

# use global syntax.syntax: glob*.pyc*.pyo*~

# switch to regular expressions syntax.syntax: regexp^\.pc/

Page 45: GTALUG Short Talk On Mercurial

Find out more...

• http://mercurial.selenic.com

Page 46: GTALUG Short Talk On Mercurial

Other cool stuff...

• Google Code (http://code.google.com/p)

• Bitbucket (http://bitbucket.org)