mercurial - icl utkmgates3/docs/mercurial-tutorial.pdf · configuration • user: ~/.hgrc • repo:...

76
Mercurial Tutorial Mark Gates Nov 2016 1

Upload: others

Post on 09-Oct-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Mercurial Tutorial

Mark GatesNov 2016

1

Page 2: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Outline• Basic commands in single repository • Creating repo

• Add & edit files

• Viewing history

• Fixing last commit

• Multiple users / branches • Simple case

• Merge without conflicts

• Merge with conflicts

• Bookmarks

• Branches

• BitBucket • Fork

• Pull requests

• Final thoughts

2

Page 3: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

• Distributed source control management • Each user has copy of entire repository • Commits go to local repo • Push & pull between repos

• Similar to git

!

• We use central repo on BitBucket to synchronize • Nothing special about BitBucket repo! !

• Unlike svn, where all commits go to server

svnserver

Chris Julia

Chris Julia

Overview of Mercurial

3

hg

svn

server masterserver

Page 4: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Help!• Extensive help • hg # basic commands • hg help [-v] # all commands • hg help command [-v] # specific command

4

>>hgMercurialDistributedSCM!basiccommands:!addaddthespecifiedfilesonthenextcommitannotateshowchangesetinformationbylineforeachfileclonemakeacopyofanexistingrepositorycommitcommitthespecifiedfilesoralloutstandingchangesdiffdiffrepository(orselectedfiles)exportdumptheheaderanddiffsforoneormorechangesetsforgetforgetthespecifiedfilesonthenextcommitinitcreateanewrepositoryinthegivendirectory...!(use"hghelp"forthefulllistofcommandsor"hg-v"fordetails)

* throughout, output is abbreviated to fit on slides

>>hghelpMercurialDistributedSCM!listofcommands:!addaddthespecifiedfilesonthenextcommitaddremoveaddallnewfiles,deleteallmissingfilesannotateshowchangesetinformationbylineforeachfilearchivecreateanunversionedarchiveofarepositoryrevisionbackoutreverseeffectofearlierchangesetbisectsubdivisionsearchofchangesetsbookmarkscreateanewbookmarkorlistexistingbookmarksbranchsetorshowthecurrentbranchnamebrancheslistrepositorynamedbranchesbundlecreateachangegroupfilecatoutputthecurrentorgivenrevisionoffiles...

>>hghelpaddhgadd[OPTION]...[FILE]...!addthespecifiedfilesonthenextcommit!Schedulefilestobeversioncontrolledandaddedtotherepository.!Thefileswillbeaddedtotherepositoryatthenextcommit.Toundoanaddbeforethat,see'hgforget'.!options([+]canberepeated):!-I--includePATTERN[+]includenamesmatchingthegivenpatterns-X--excludePATTERN[+]excludenamesmatchingthegivenpatterns-n--dry-rundonotperformactions,justprintoutput!(somedetailshidden,use--verbosetoshowcompletehelp)

>>hg--versionMercurialDistributedSCM(version3.9.2)(seehttps://mercurial-scm.orgformoreinformation)!!!!!!!!!!!!!

Page 5: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Configuration• User: ~/.hgrc

• Repo: .hg/hgrc

• Suggested items • ~/.hgignore hides files in

hg status output • external diff (e.g., graphical) • git diff output nicer when

renaming files • color extension colors diff

and status output • shelve saves changes

temporarily • alias to shorten commands

5

[ui]ignore=~/.hgignore![extensions]hgext.extdiff=color=shelve=![extdiff]cmd.opendiff=fmdiff![diff]git=True!#https://www.mercurial-scm.org/wiki/ColorExtension[color]status.ignored=blackstatus.modified=boldbluestatus.added=boldgreenstatus.removed=boldmagentastatus.deleted=boldredstatus.unknown=black!diff.tab=red_backgrounddiff.trailingwhitespace=red_background![alias]glog=log-Gslog=log--template=short

~/.hgrc

syntax:glob!#latexoutputfiles*.aux*.bbl*.blg*.fff*.idx*.log*.marks*.nav*.out*.snm*.synctex.gz*.toc!#compiledfiles*.a*.d*.o*.pyc*.so!#hgbackupfiles*.orig!#miscfiles.DS_Store

~/.hgignore

Page 6: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Creating repo!

• hg init [directory]

• Creates repo directory (if needed) and .hg directory

• By default uses current “.” directory

6

home>hginitrecipeshome>cdrecipes/recipes>ls-a./../.hg/

Page 7: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Adding files• hg add [files]

• hg status [-acm] [-q] # hg st • -a added • -c clean • -m modified • -q quiet (hide unknown files)

• hg commit [-m “message”]

7

recipes>jeditpizza.txtrecipes>hgaddpizza.txtrecipes>hgstApizza.txt#A=added!recipes>hgcommit-m'startpizza’

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Page 8: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Editing files• hg diff [files]

8

recipes>jeditpizza.txtrecipes>hgstMpizza.txt#M=modified!recipes>hgdiffdiff-r9ab04aa4c434pizza.txt---a/pizza.txt TueOct2507:58:392016-0400+++b/pizza.txt TueOct2508:03:532016-0400@@-1,7+1,7@@Dough-11/2cupswarmwater(105°F–115°F)+1.5cupswarmwater(105°F–115°F)1packageactivedryyeast-31/2cupsbreadflour+3.5cupsbreadflour2Tbspoliveoil2tspsalt1tspsugar!recipes>hgcommit-m'usedecimal'

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Page 9: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

History

9

• hg diff -r revision • Working files compared to that revision

• hg diff -c revision • Changes that occurred in that revision

recipes>hgdiff#orrecipes>hgdiff-r1diff-r0b85839d8a57pizza.txt---a/pizza.txt TueOct2508:05:452016-0400+++b/pizza.txt TueOct2511:42:242016-0400@@-9,6+9,7@@2/3cuptomatosauce2/3cupmozzarellacheese,grated+1/3cupfetacheese,crumbledMixdoughingredients;kneadfor10minutes.

recipes>hgdiff-c1diff-r9ab04aa4c434-r0b85839d8a57pizza.txt---a/pizza.txt TueOct2507:58:392016-0400+++b/pizza.txt TueOct2508:05:452016-0400@@-1,7+1,7@@Dough-11/2cupswarmwater(105°F–115°F)+1.5cupswarmwater(105°F–115°F)1packageactivedryyeast-31/2cupsbreadflour+3.5cupsbreadflour2Tbspoliveoil2tspsalt1tspsugar@@-11,7+11,7@@2/3cupmozzarellacheese,grated

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with

pizza.txt

Page 10: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

recipes>hglog--statchangeset:1:0b85839d8a57user:[email protected]:TueOct2508:05:452016-0400summary:usedecimal!pizza.txt|6+++---1fileschanged,3insertions(+),3deletions(-)!changeset:0:9ab04aa4c434user:[email protected]:TueOct2507:58:392016-0400summary:startpizza!pizza.txt|17+++++++++++++++++1fileschanged,17insertions(+),0deletions(-)

History• hg log [-l num] [-G] [--stat]

• -l limit to last num commits • -G graph • --stat show files changed

• commits identified 2 ways • Local version number

(0, 1, 2, ...) • Local only! Different for

different users • Global unique hash

(e.g., 0b85839d8a57)

10

recipes>hglogchangeset:1:0b85839d8a57user:[email protected]:TueOct2508:05:452016-0400summary:usedecimal!changeset:0:9ab04aa4c434user:[email protected]:TueOct2507:58:392016-0400summary:startpizza

• Terminology: commits == revisions == changesets

Page 11: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

History• Customizable log templates

• hg log --template list # show available templates

• Examples • http://hgtip.com/tips/advanced/2010-01-15-styling-mercurials-cli/

• Custom

11

recipes>hglog--template=custom95231fa16d6472016-10-2813:16miscmgates3default8b1047ddb7fca2016-10-2811:57grindmgates3sauce@790b0579b46292016-10-2811:57onionmgates3sauce[*main]683c38f1e80dd2016-10-2811:22mergesaucemgates3default3,5[saucier]5ff3b0aca8e362016-10-2811:21sautemgates3sauce(v1.1)4f82b641f95062016-10-2811:20brandmgates3sauce31119625a97232016-10-2811:20preheatmgates3default2d82ee94655b32016-10-2811:19meatmgates3default(v1.0)149bb5328310f2016-10-2811:19startsaucemgates3sauce06ec9bb1d6c4c2016-10-2811:17startpizzamgates3default!recipes>hgslog#aliasin~/.hgrc

Page 12: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Copy, move files• hg cp source destination [-A]

• hg mv source destination [-A]

12

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/2 cup bell peppers, thinly sliced 1/2 cup chopped fresh basil 1/2 cup onions, diced !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

veggie.txtrecipes>hgcppizza.txtveggie.txtrecipes>jeditveggie.txtrecipes>hgstAveggie.txt!recipes>hgdiff#gitoptionin~/.hgrcdiff--gita/pizza.txtb/veg.txtcopyfrompizza.txtcopytoveggie.txt---a/pizza.txt+++b/veggie.txt2/3cupmozzarellacheese,grated+1/2cupbellpeppers,thinlysliced+1/2cupchoppedfreshbasil+1/2cuponions,diced!recipes>hgcommit-m'addveggie'

Page 13: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Copy, move files• hg cp source destination [-A]

• hg mv source destination [-A]

13

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/2 cup bell peppers, thinly sliced 1/2 cup chopped fresh basil 1/2 cup onions, diced !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

veggie.txtrecipes>hgmvpizza.txtveggie.txtrecipes>hgstAveggie.txt#A=addedRpizza.txt#R=removedrecipes>hgcommit-m'renametoveggie'

recipes>mvpizza.txtveggie.txtrecipes>hgst!pizza.txt#!=trackedfilemissing?veggie.txt#?=untrackedfilerecipes>hgmvpizza.txtveggie.txt-Arecipes>hgstAveggie.txtRpizza.txtrecipes>hgcommit-m'renametoveggie'

Page 14: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Remove files• hg rm files [-f] [-A]

14

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

recipes>hgrmveggie.txtrecipes>hgstRveggie.txtrecipes>hgcommit-m'removeveggie'

recipes>rmveggie.txtrecipes>hgst!veggie.txtrecipes>hgrmveggie.txt[-A]recipes>hgstRveggie.txtrecipes>hgcommit-m'removeveggie'

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/2 cup bell peppers, thinly sliced 1/2 cup chopped fresh basil 1/2 cup onions, diced !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

veggie.txt

recipes>jeditveggie.txtrecipes>hgstMveggie.txtrecipes>hgrmveggie.txtnotremovingveggie.txt:fileismodified(use-ftoforceremoval)recipes>hgrmveggie.txt-frecipes>hgstRveggie.txtrecipes>hgcommit-m'removeveggie'

Page 15: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Reverting changes• hg revert files

15

recipes>hgcppizza.txtsupreme.txtrecipes>hgrmveggie.txtrecipes>jeditpizza.txtrecipes>hgstMpizza.txtAsupreme.txtRveggie.txt!recipes>hgrevertpizza.txtrecipes>hgstAsupreme.txtRveggie.txt!recipes>hgrevert.#“.”directoryforgettingsupreme.txtundeletingveggie.txt!recipes>hgst?supreme.txt!recipes>ls-1pizza.txtpizza.txt.orig#backupsupreme.txt#backupveggie.txt

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated italian sausage, cooked mushrooms, thinly sliced bell peppers, thinly sliced chopped fresh basil pesto pepporoni onions, diced ham, diced !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

supreme.txtDough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/2 cup bell peppers, thinly sliced 1/2 cup chopped fresh basil 1/2 cup onions, diced !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

veggie.txt

Teig 1,5 Tassen warmes Wasser (105 ° F-115 ° F) 1 Packung aktive Trockenhefe 3,5 Tassen Brotmehl 2 EL Olivenöl 2 TL Salz 1 TL Zucker !Toppings 2/3 Tasse Tomatensoße 2/3 Tasse Mozzarella, gerieben !Mix Teig Zutaten; 10 Minuten kneten. Abdeckung; Steigen bis doppelt, ca. 1-1,5 Stunden. Teig in der Hälfte teilen; Roll-out bis 10-12 Zoll Durchmesser. Mit Tomatensauce bestreichen und mit Toppings bestreuen. Backen Sie jeweils bei 450 ° F für 10-15 Minuten, bis golden.

pizza.txt

Dough 1.5 cups warm water (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Page 16: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Fixing last commit (only last!)• hg rollback

16

recipes>jeditveggie.txtrecipes>jeditpizza.txtrecipes>hgstMpizza.txtMveggie.txtrecipes>hgcommit-m'H20'recipes>hglog-l2changeset:5:22456188656dtag:tipsummary:H20!changeset:4:7a81b46fbf59summary:renametoveggie!recipes>hgrollbackrepositorytiprolledbacktorevision4(undocommit)workingdirectorynowbasedonrevision4!recipes>hglog-l2changeset:4:7a81b46fbf59tag:tipsummary:renametoveggie!recipes>hgstMpizza.txtMveggie.txt

Dough 1.5 cups warm H20 (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Dough 1.5 cups warm H20 (105 °F–115 °F) 1 package active dry yeast 3.5 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/2 cup bell peppers, thinly sliced 1/2 cup chopped fresh basil 1/2 cup onions, diced !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1.5 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

veggie.txt

Page 17: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Fixing last commit (only last!)• hg commit --amend • Destroys rollback information • Changes global hash identifier, but not date • Can change message

17

recipes>jeditveggie.txtrecipes>jeditpizza.txtrecipes>hgstMpizza.txtMveggie.txtrecipes>hgcommit-m'H20'pizza.txtrecipes>hgstMveggie.txt!recipes>hglog-l1--statchangeset:5:167f86be8569tag:tipdate:TueOct2511:01:212016-0400summary:H20!pizza.txt|2+-1fileschanged,1insertions(+),1deletions(-)

recipes>hgcommit--amendveggie.txtsavedbackupbundleto/Users/mgates/Documents/writing/2016/mercurial/recipes/.hg/strip-backup/167f86be8569-954506e9-amend-backup.hg!recipes>hgstrecipes>

!!recipes>hglog-l1--statchangeset:5:65d210f5f675tag:tipdate:TueOct2511:01:212016-0400summary:H20!pizza.txt|2+-veggie.txt|2+-2fileschanged,2insertions(+),2deletions(-)

Page 18: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Outline• Basic commands in single repository • Creating repo

• Add & edit files

• Viewing history

• Fixing last commit

• Multiple users / branches • Simple case

• Merge without conflicts

• Merge with conflicts

• Bookmarks

• Branches

• BitBucket • Fork

• Pull requests

• Final thoughts

18

Page 19: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

3 kinds of branches• Forks (or clones) — copies of repo • Every copy is a fork! You cannot avoid branching! • Typically for development; periodically synchronize • Same as git forking

• Bookmarks • Typically short-lived for feature development • Same as git’s branches

• Named branches • Typically long-lived branches like “stable” and “devel” • Branch name permanently recorded in commit log

19

Page 20: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Simple example — one person editing at a time

20

Page 21: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

• Simple example with only one person editing at a time

• hg clone url [directory]

• hg push [url]

• hg pull [url] [-u]

• hg update # hg up server

Chris Julia

update

commit

pushpull

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Basic server interaction

21

clone

0 1

2 3

pullclone

0: pizza 1: feta

2: meat 3: preheat

0 1

push

2 3

push

Page 22: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Basic server interaction

22

home>hgclonessh://server/recipeschrishome>cdchrischris>ls-a./../.hg/

[paths]default=ssh://server/recipes

.hg/hgrc

clone

Page 23: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Basic server interaction

23

home>hgclonessh://server/recipeschrishome>cdchris!chris>jeditpizza.txtchris>hgcommit-m‘startpizza'chris>jeditpizza.txtchris>hgcommit-m‘feta'chris>hgpushpushingtossh://server/recipesmercurial/recipessearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1files

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

clone

0: pizza 1: feta

0 1

push

Page 24: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Basic server interaction

24

home>hgclonessh://server/recipesjuliahome>cdjulia!julia>jeditpizza.txtjulia>hgcommit-m‘meat'julia>hgcommit-m‘preheat'julia>hgpushpushingtossh://server/recipessearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1files

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled 1/2 cup Italian sausage, cooked 1/4 cup pepperoni !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled 1/2 cup Italian sausage, cooked 1/4 cup pepperoni !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Preheat oven to 450 °F. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

clone

0: pizza 1: feta

0 1

push

clone

0 1 2: meat 3: preheat

2 3

push

Page 25: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Basic server interaction

25

chris>hgpullpullingfromssh://server/recipessearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1files(run'hgupdate'togetaworkingcopy)

chris>hgpull-upullingfromssh://server/recipessearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1files1filesupdated,0filesmerged,0filesremoved,0filesunresolved

– or –

chris>hgup1filesupdated,0filesmerged,0filesremoved,0filesunresolved

clone

0: pizza 1: feta

0 1

push

clone

0 1 2: meat 3: preheat

2 3

push

2 3

pull

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled 1/2 cup Italian sausage, cooked 1/4 cup pepperoni !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Preheat oven to 450 °F. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txtNote that working copy not yet updated!

Page 26: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Simple merge — two simultaneous edits, without conflicts

26

Page 27: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Merge without conflicts• Merge is required if edits happen in parallel

• Local commit numbers differ

• hg merge

27

4: veg

4: ham

4: veg

push

push pull

5: veg6: merge

push

5: ham6: merge

pull

5: ham 6: merge

0:3

0:3

0:3

Page 28: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Merge

28

4: veg

push

push

chris>jeditpizza.txtchris>hgcommit-m‘veggies'chris>hgpush

julia>jeditpizza.txtjulia>hgcommit-m‘ham'julia>hgpushpushingtossh://server/recipessearchingforchangesremotehasheadsonbranch'default'thatarenotknownlocally:7dc71c9ebfc4abort:pushcreatesnewremoteheadc7f726f74e9a!(pullandmergeorsee"hghelppush"fordetailsaboutpushingnewheads)

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled 1/4 cup mushrooms, thinly sliced 1/4 cup bell peppers, thinly sliced 1/2 cup Italian sausage, cooked 1/4 cup pepperoni !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Preheat oven to 450 °F. Divide dough in half; roll out to 10–12 inches diameter.

pizza.txt

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/3 cup feta cheese, crumbled 1/2 cup Italian sausage, cooked 1/4 cup pepperoni 1/4 cup ham !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Preheat oven to 450 °F. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings.

pizza.txt

4: ham

4: veg

0:3

0:3

0:3

Page 29: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Merge

29

4: veg

4: ham

4: veg

push

push pull

5: veg6: merge

julia>hgpullpullingfromssh://server/recipessearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files(+1heads)(run'hgheads'toseeheads,'hgmerge'tomerge)!julia>hgup#warning,doesnothing0filesupdated,0filesmerged,0filesremoved,0filesunresolved1otherheadsforbranch"default"

julia>hgmergemergingpizza.txt0filesupdated,1filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)

0:3

0:3

0:3

Page 30: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Merge — verify & commit!

30

4: veg

4: ham

4: veg

push

push pull

5: veg6: merge

push

5: ham6: merge

julia>hgheadschangeset:5:962db491f9casummary:veggies!changeset:4:b1473e48944esummary:ham!julia>hgdiff-r4@@-10,8+10,6@@1/3cupfetacheese,crumbled+1/4cupmushrooms,thinlysliced+1/4cupbellpeppers,thinlysliced1/2cupItaliansausage,cooked

julia>hgdiff-r5@@-14,7+14,6@@1/2cupItaliansausage,cooked1/4cuppepperoni+1/4cupham!julia>hgcommit-m‘merge'julia>hgpush#optionalpushingtossh://server/recipessearchingforchangesaddingchangesetsaddingfilechangesadded2changesetswith2changesto1files

0:3

0:3

0:3

Page 31: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Server:

Chris:

Julia:

dashed lines are copies solid lines are dependencies

Merge

31

4: veg

4: ham

4: veg

push

push pull

5: veg6: merge

push

5: ham6: merge

pull

5: ham 6: merge

chris>hgpullpullingfrom/Users/mgates/Documents/writing/2016/mercurial/recipessearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1files(run'hgupdate'togetaworkingcopy)!chris>hgup1filesupdated,0filesmerged,0filesremoved,0filesunresolved

0:3

0:3

0:3

Page 32: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Conflict merge — two simultaneous edits to same text

32

Page 33: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Merge with conflict• Simplify recipe slightly, then add ingredients in same spot

33

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/4 cup mushrooms, sliced 1/4 cup onions, diced 1/2 cup Italian sausage, cooked !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Preheat oven to 450 °F. Divide dough in half; spin in air to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

pizza.txt

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp olive oil 2 tsp salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/2 cup Italian sausage, cooked !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Preheat oven to 450 °F. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp extra virgin olive oil 2 tsp sea salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated 1/2 cup bell peppers, thinly sliced 1/3 cup mushrooms 1/2 cup Italian sausage, cooked !Mix dough ingredients; knead for 10 minutes. Cover; rise until double, about 1–1 1/2 hours. Preheat oven to 450 °F. Divide dough in half; roll out to 10–12 inches diameter. Spread with tomato sauce & sprinkle with toppings. Bake each at 450 °F for 10–15 minutes until golden.

pizza.txt

Page 34: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

• Graphical diff (here, Apple’s FileMerge, i.e., opendiff)

• Non-conflicting portions mergedautomatically

• Manually resolve conflicting portions • Choose left, right,

both, or neither • See & edit final text

in bottom pane

• Save file & quit

Merge with conflict: graphical

34

julia>hgmergemergingpizza.txt0filesupdated,1filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)

Page 35: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

35

Your code

Incoming code

Merged code

Page 36: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

36

Your code

Incoming code

Merged code

• Save file & quit

Page 37: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Merge with conflict: verify & commit!

37

julia>hgheadschangeset:9:f41d23390194summary:peppers!changeset:8:791c8abf0a1dsummary:onions!julia>hgdiff-r831/2cupsbreadflour-2Tbspoliveoil-2tspsalt+2Tbspextravirginoliveoil+2tspseasalt1tspsugar!2/3cupmozzarellacheese,grated-1/4cupmushrooms,sliced+1/2cupbellpeppers,thinlysliced+1/3cupmushrooms,sliced1/4cuponions,diced

julia>hgdiff-r91/2cupbellpeppers,thinlysliced-1/3cupmushrooms+1/3cupmushrooms,sliced+1/4cuponions,diced1/2cupItaliansausage,cooked!Preheatovento450°F.-Dividedoughinhalf;rolloutto10–12inchesdiameter.+Dividedoughinhalf;spininairto10–12inchesdiameter.Spreadwithtomatosauce&sprinklewithtoppings.!julia>hgcommit-m‘merge’

Page 38: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Merge with conflict: manual• hg resolve [-l, -m, -u] [files] • -l list resolved status • -m mark as resolved • -u mark as unresolved

38

julia>hgmerge--toolinternal:mergemergingpizza.txtwarning:conflictswhilemergingpizza.txt!(edit,thenuse'hgresolve--mark')0filesupdated,0filesmerged,0filesremoved,1filesunresolveduse'hgresolve'toretryunresolvedfilemergesor'hgupdate-C.'toabandon!julia>hgcommit-m'merge'abort:unresolvedmergeconflicts(see"hghelpresolve")!julia>hgresolve-l#listresolvedstatusUpizza.txt#U=unresolved!julia>jeditpizza.txtjulia>hgresolve-mpizza.txt#markasresolved(nomoreunresolvedfiles)!julia>hgresolve-lRpizza.txt#R=resolved!julia>hgcommit-m‘merge’

Dough 1 1/2 cups warm water (105 °F–115 °F) 1 package active dry yeast 3 1/2 cups bread flour 2 Tbsp extra virgin olive oil 2 tsp sea salt 1 tsp sugar !Toppings 2/3 cup tomato sauce 2/3 cup mozzarella cheese, grated <<<<<<< local 1/4 cup mushrooms, sliced 1/4 cup onions, diced ======= 1/2 cup bell peppers, thinly sliced 1/3 cup mushrooms >>>>>>> other 1/2 cup Italian sausage, cooked !Mix dough ingredients; knead for 10 minutes.

pizza.txt

Page 39: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

History• hg log -G # graph branches

• hg glog # alias in ~/.hgrc

39

chris>hglog-G@changeset:10:10ae7218a2bd|\tag:tip||parent:9:791c8abf0a1d||parent:8:f41d23390194||summary:merge|||ochangeset:9:791c8abf0a1d||parent:7:1b946d5db238||summary:onions||o|changeset:8:f41d23390194|/summary:peppers|ochangeset:7:1b946d5db238|summary:basic|...!

|ochangeset:6:800444945b16|\parent:5:b1473e48944e||parent:4:962db491f9ca||summary:merge|||ochangeset:5:b1473e48944e||parent:3:0f66f034fa18||summary:ham||o|changeset:4:962db491f9ca|/summary:veggies|ochangeset:3:0f66f034fa18|summary:preheat|ochangeset:2:7d60311ab431|summary:meat|ochangeset:1:92dafa80df69|summary:feta|ochangeset:0:9ab04aa4c434summary:startpizza

Page 40: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Solving merge problems

40

Page 41: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Fixing bad merge (option 1)• hg update --clean • Reverts all files to state before “hg merge” command !!!!!!!!

!

• Can then do “hg merge” again

41

julia>hgmergemergingpizza.txt2016-11-0401:24:24.700FileMerge[21657:d07]InvalidcolorSystem,labelColor(warninggivenonlyonce)0filesupdated,1filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)!#utterconfusionentails!julia>hgupabort:outstandinguncommittedmerge!julia>hgstMpizza.txt!julia>hgupdate--clean1filesupdated,0filesmerged,0filesremoved,0filesunresolved1otherheadsforbranch“default"!julia>hgstjulia>

Page 42: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Fixing bad merge (option 2)• Alternatively, redo merge of specific files

• hg resolve -u files # mark files as unresolved

• hg resolve files # re-merge files

42

julia>hgmergemergingpizza.txt2016-11-0401:26:51.567FileMerge[21675:d07]InvalidcolorSystem,labelColor(warninggivenonlyonce)0filesupdated,1filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)!julia>hgresolve-lRpizza.txt#R=resolvedjulia>hgresolve-upizza.txtjulia>hgresolve-lUpizza.txt#U=unresolved!julia>hgresolvepizza.txtmergingpizza.txt2016-11-0401:28:11.805FileMerge[21690:d07]InvalidcolorSystem,labelColor(warninggivenonlyonce)(nomoreunresolvedfiles)julia>hgstMpizza.txtjulia>hgcommit-m'merge'

Page 43: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Merge with uncommitted changes• hg won’t merge if there

are uncommitted changes

• Either commit them, or shelve them temporarily

• hg shelve [-n name] [-l]

• hg unshelve [name]

• Extension in ~/.hgrc

!

!

• (Similar to git stash)

43

recipes>hgstMpizza.txt!recipes>hgmergeabort:uncommittedchanges(use'hgstatus'tolistchanges)!recipes>hgshelve-npeppersshelvedaspeppers1filesupdated,0filesmerged,0filesremoved,0filesunresolved!recipes>hgstrecipes>hgshelve-lpeppers(4sago)changesto:meat!recipes>hgmergemergingpizza.txt0filesupdated,1filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)recipes>hgcommit-m'merge'!recipes>hgunshelve[peppers]unshelvingchange'peppers'rebasingshelvedchangesrebasing4:8be446f41b74"changesto:meat"(tip)mergingpizza.txtrecipes>hgstMpizza.txt

Page 44: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Bookmarks

44

Page 45: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks15: merge• Bookmark is label that

tracks head of a branch

• Add, delete, and rename at any time

• Typically for short-lived feature or bug-fix branches

• Essentially same as git’s branches

45

mainsauce

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge12: ham

13: spin 14: chop

main

main

main

main

main

main

main

sauce

sauce

sauce

sauce

sauce

sauce

sauce

Page 46: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

• hg bookmark[s] # lists bookmarks

• hg bookmark name # creates bookmark

• hg update name # updates working copy to bookmark

Branching with Bookmarks

46

mainsauce

0: pizza

1: feta

recipes>jeditpizza.txtrecipes>hgaddpizza.txtrecipes>hgcommit-m'pizza'!recipes>jeditpizza.txtrecipes>hgcommit-m'feta'!recipes>hgbookmarkmainrecipes>hgbookmarksaucerecipes>hgbookmarksmain1:a1f2a82ea6e0*sauce1:a1f2a82ea6e0

Page 47: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks

47

mainsauce

0: pizza

1: feta

2: sauce

3: brand

sauce

sauce

recipes>jeditsauce.txtrecipes>hgaddsauce.txtrecipes>hgcommit-m'sauce'!recipes>jeditsauce.txtrecipes>hgcommit-m'brand'recipes>lspizza.txtsauce.txt!recipes>hgslog-G@@3branddefault[*sauce](tip)|o2saucedefault|o1fetadefault[main]|o0pizzadefault

Page 48: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks

48

main

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat

main

main

sauce

recipes>hgupmain0filesupdated,0filesmerged,1filesremoved,0filesunresolved(activatingbookmarkmain)recipes>lspizza.txt!recipes>jeditpizza.txtrecipes>hgcommit-m'meat'creatednewhead!recipes>hgcommit-m'preheat'recipes>hgslog-G@@5preheatdefault[*main](tip)|o4meatdefault||o3branddefault[sauce]|||o2saucedefault|/o1fetadefault|o0pizzadefault

Page 49: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks

49

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sautémain

sauce

sauce

recipes>hgupsauce2filesupdated,0filesmerged,0filesremoved,0filesunresolved(activatingbookmarksauce)recipes>hgslog-Go5preheatdefault[main]|o4meatdefault||@@3branddefault[*sauce]|||o2saucedefault|/o1fetadefault|o0pizzadefault!recipes>jeditsauce.txtrecipes>hgcommit-m'saute'recipes>hgslog-G@@6sautedefault[*sauce]||o5preheatdefault[main]|||o4meatdefault||o|3branddefault||o|2saucedefault|/o1fetadefault|o0pizzadefault

Page 50: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks

50

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

main

main

sauce

recipes>hgupmain1filesupdated,0filesmerged,1filesremoved,0filesunresolved(activatingbookmarkmain)recipes>hgslog-Go6sautedefault[sauce]||@@5preheatdefault[*main]||!recipes>hgmergesauce1filesupdated,0filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)recipes>stMsauce.txtrecipes>hgcommit-m'mergesauce'recipes>hgslog-G@@7mergesaucedefault5,6[*main]|\|o6sautedefault[sauce]||o|5preheatdefault||o|4meatdefault|||o3branddefault|||o2saucedefault|/o1fetadefault|o0pizzadefault

Page 51: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks

51

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

main

main

sauce

sauce

sauce

recipes>hgbookmark*main7:92bf22ea6bd9sauce6:058a19c7aec7recipes>jeditpizza.txtrecipes>hgcommit-m'parmesan'!recipes>hgupsauce1filesupdated,0filesmerged,0filesremoved,0filesunresolved(activatingbookmarksauce)recipes>jeditsauce.txtrecipes>hgcommit-m'onion'creatednewhead!recipes>hgcommit-m'peeled'recipes>hgslog-G@@10peeleddefault[*sauce]|o9oniondefault||o8parmesandefault[main]|||o7mergesaucedefault5,6|/|o|6sautedefault|||o5preheatdefault|||o4meatdefault||

Page 52: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks

52

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge

mainsauce

sauce

recipes>hgmergemain1filesupdated,0filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)recipes>hgstMpizza.txtrecipes>hgcommit-m'mergemain'recipes>hgslog-G@@11mergemaindefault10,8[*sauce]|\|o10peeleddefault|||o9oniondefault||o|8parmesandefault[main]||o|7mergesaucedefault5,6|\||o6sautedefault||o|5preheatdefault||o|4meatdefault|||o3branddefault|||o2saucedefault|/o1fetadefault|o0pizzadefault

Page 53: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks15: merge

53

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge12: ham

13: spin 14: chop

main

main

main

main

sauce

recipes>hgupmain1filesupdated,0filesmerged,0filesremoved,0filesunresolved(activatingbookmarkmain)!recipes>jeditpizza.txtrecipes>hgcommit-m'ham'creatednewhead!recipes>jeditpizza.txtrecipes>hgcommit-m'spin'!recipes>hgupsauce2filesupdated,0filesmerged,0filesremoved,0filesunresolved(activatingbookmarksauce)recipes>jeditsauce.txtrecipes>hgcommit-m'chop'!recipes>hgupmain2filesupdated,0filesmerged,0filesremoved,0filesunresolved(activatingbookmarkmain)!recipes>hgmergesauce1filesupdated,0filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)recipes>hgcommit-m'mergesauce'

sauce

Page 54: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks15: merge

54

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge12: ham

13: spin 14: chop

main

sauce

recipes>hgbookmark--deletesaucerecipes>hgslog-G@@15mergesaucedefault13,14[*main]|\|o14chopdefault||o|13spindefault||o|12hamdefault|||o11mergemaindefault10,8|/||o10peeleddefault|||o9oniondefault||o|8parmesandefault||o|7mergesaucedefault5,6|\||o6sautedefault||o|5preheatdefault||o|4meatdefault|||o3branddefault|||o2saucedefault|/o1fetadefault|o0pizzadefault

Page 55: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Pushing bookmarks• hg doesn’t push new bookmarks by default

• hg push {--bookmark|-B} bookmark

55

recipes>hgpushpushingtoserversearchingforchangesabort:pushcreatesnewremotehead42ca2b91c349withbookmark'sauce'!(mergeorsee"hghelppush"fordetailsaboutpushingnewheads)!recipes>hgpush--bookmarkmain#or-Bpushingto../c2searchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1filesexportingbookmarkmain!recipes>hgpush--bookmarksauce#or-Bpushingto../c2searchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1files(+1heads)exportingbookmarksauce

Page 56: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Merging divergent bookmarks• Chris & Julia both make changes in sauce branch,

Julia pulls in new head as sauce@default

56

julia>hgpull-upullingfromserversearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files(+1heads)divergentbookmarksaucestoredassauce@default0filesupdated,0filesmerged,0filesremoved,0filesunresolved1otherdivergentbookmarksfor"sauce"!julia>hgheadschangeset:10:207f29b01f7bbookmark:sauce@defaultparent:8:b6b112e27e33summary:finely!changeset:9:566cd34821bcbookmark:saucesummary:vidalia!changeset:2:8f439fe17062bookmark:mainsummary:pepperoni

julia>hgmergeabort:nomatchingbookmarktomerge-pleasemergewithanexplicitrevorbookmark(run'hgheads'toseeallheads)!julia>hgupsauce2filesupdated,0filesmerged,0filesremoved,0filesunresolved(activatingbookmarksauce)!julia>hgbookmarksmain4:8f439fe17062*sauce12:4d0841e8279dsauce@default13:bd2c99f8da7f!julia>hgmergemergingsauce.txt0filesupdated,1filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)!julia>hgcommit-m'merge'

Page 57: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Named Branches

57

Page 58: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches15: merge• Branch is permanent name

attached to each commit

• “default” branch

• Typically for long-lived branches like “stable” and “devel”

• Operate similarly to bookmarks

58

default

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge12: ham

13: spin 14: chop

default

default

default

default

default

default

default

sauce

sauce

sauce

sauce

sauce

sauce

sauce

default

Page 59: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

• hg branches # lists branches

• hg branch name # creates branch

• hg update name # updates working copy to branch

• hg commit --close-branch [-m “message”]

Branching with Named Branches

59

default

0: pizza

1: feta

recipes>jeditpizza.txtrecipes>hgaddpizza.txtrecipes>hgcommit-mpizza!recipes>jeditpizza.txtrecipes>hgcommit-mfeta!recipes>hgbranchsaucemarkedworkingdirectoryasbranchsauce(branchesarepermanentandglobal,didyouwantabookmark?)!recipes>hgbranches#newbranchnotyetvisibledefault1:98b3df1d5afe default

Page 60: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Bookmarks

60

default

0: pizza

1: feta

2: sauce

3: brand

sauce

sauce

recipes>jeditsauce.txtrecipes>hgaddsauce.txtrecipes>hgcommit-mstartsaucerecipes>hgbranches#newbranchvisiblesauce2:2a5c5e403030default1:98b3df1d5afe(inactive)!recipes>jeditsauce.txtrecipes>hgcommit-m'brand'recipes>lspizza.txtsauce.txt!recipes>hgslog-G@@3brandsauce|o2startsauce|o1fetadefault|o0pizzadefault

default

Page 61: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches

61

default

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat

default

default

sauce

recipes>hgupdefault0filesupdated,0filesmerged,1filesremoved,0filesunresolved!recipes>lspizza.txt!recipes>jeditpizza.txtrecipes>hgcommit-m'meat'!recipes>hgcommit-m'preheat'recipes>hgslog-G@@5preheatdefault|o4meatdefault||o3brandsauce|||o2startsauce|/o1fetadefault|o0pizzadefault

default

sauce

Page 62: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches

62

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sautédefault

sauce

sauce

recipes>hgupsauce2filesupdated,0filesmerged,0filesremoved,0filesunresolved!recipes>hgslog-Go5preheatdefault|o4meatdefault||@@3brandsauce|||o2startsauce|/o1fetadefault|o0pizzadefault!recipes>jeditsauce.txtrecipes>hgcommit-m'saute'recipes>hgslog-G@@6sautesauce||o5preheatdefault|||o4meatdefault||o|3brandsauce||o|2startsauce|/o1fetadefault|o0pizzadefault

default

default

default sauce

Page 63: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches

63

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

default

default

sauce

recipes>hgupdefault1filesupdated,0filesmerged,1filesremoved,0filesunresolved!recipes>hgslog-Go6sautesauce||@@5preheatdefault||!recipes>hgmergesauce1filesupdated,0filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)recipes>hgstMsauce.txtrecipes>hgcommit-m'mergesauce'recipes>hgslog-G@@7mergesaucedefault5,6|\|o6sautesauce||o|5preheatdefault||o|4meatdefault|||o3brandsauce|||o2startsauce|/o1fetadefault|o0pizzadefault

default

sauce

sauce

default

default

Page 64: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches

64

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

default

default

sauce

sauce

sauce

recipes>hgbranchessauce2:2a5c5e403030(inactive)default1:98b3df1d5aferecipes>jeditpizza.txtrecipes>hgcommit-m'parmesan'!recipes>hgupsauce1filesupdated,0filesmerged,0filesremoved,0filesunresolved!recipes>jeditsauce.txtrecipes>hgcommit-m'onion'!recipes>hgcommit-m'peeled'recipes>hgslog-G@@10peeledsauce|o9onionsauce||o8parmesandefault|||o7mergedefault5,6|/|o|6sautesauce|||o5preheatdefault|||o4meatdefault||

default

sauce

sauce

default

default

default

Page 65: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches

65

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge

defaultsauce

sauce

recipes>hgmergedefault1filesupdated,0filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)recipes>hgstMpizza.txtrecipes>hgcommit-m'mergedefault'recipes>hgslog-G@@11mergesauce10,8|\|o10peeledsauce|||o9onionsauce||o|8parmesandefault||o|7mergedefault5,6|\||o6sautesauce||o|5preheatdefault||o|4meatdefault|||o3brandsauce|||o2startsauce|/o1fetadefault|o0pizzadefault

default

sauce

sauce

sauce

sauce

default

default

default

default

Page 66: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches15: merge

66

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge12: ham

13: spin 14: chop

default

default

default

default

sauce

recipes>hgupdefault1filesupdated,0filesmerged,0filesremoved,0filesunresolved!recipes>jeditpizza.txtrecipes>hgcommit-m'ham'!recipes>jeditpizza.txtrecipes>hgcommit-m'spin'!recipes>hgupsauce2filesupdated,0filesmerged,0filesremoved,0filesunresolvedrecipes>jeditsauce.txtrecipes>hgcommit-m‘chop'--close-branch!recipes>hgbranchesdefault15:dd9a3e61378b!recipes>hgbranches--closed#or-cdefault15:dd9a3e61378bsauce14:c6e4f6cf0870(closed)!recipes>hgupdefault2filesupdated,0filesmerged,0filesremoved,0filesunresolved!recipes>hgmergesauce1filesupdated,0filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)recipes>hgcommit-m'mergesauce'

sauce

default

sauce

sauce

sauce

sauce

sauce

default

default

default

default

Page 67: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Branching with Named Branches15: merge

67

0: pizza

1: feta

2: sauce4: meat

3: brand

5: preheat 6: sauté

7: merge

8: parm.9: onion

10: peel

11: merge12: ham

13: spin 14: chop

default

sauce

recipes>hgslog-G@@15mergedefault13,14|\|_14chopsauce||o|13spindefault||o|12hamdefault|||o11mergesauce10,8|/||o10peeledsauce|||o9onionsauce||o|8parmesandefault||o|7mergedefault5,6|\||o6sautesauce||o|5preheatdefault||o|4meatdefault|||o3brandsauce|||o2startsauce|/o1fetadefault|o0pizzadefault

default

sauce

sauce

sauce

sauce

sauce

sauce

default

default

default

default

default

default

defaultclosed branch

Page 68: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Pushing branches• hg doesn’t push new branches by default

• hg pushes all branches by default • (git pushes only the current branch, which makes more sense to me)

• hg push [-b branch] [--new-branch]

68

recipes>hgpushpushingtoserversearchingforchangesabort:pushcreatesnewremotebranches:sauce!(use'hgpush--new-branch'tocreatenewremotebranches)!recipes>hgpush-bdefaultpushingtoserversearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files!recipes>hgpush-bsauce--new-branchpushingtoserversearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded2changesetswith2changesto1files(+1heads)

Page 69: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Merging branch heads

69

julia>hgpullpullingfromserversearchingforchangesaddingchangesetsaddingmanifestsaddingfilechangesadded1changesetswith1changesto1files(+1heads)(run'hgheads'toseeheads,'hgmerge'tomerge)!julia>hgbranchessauce4:75a9cc02c946default1:df75056e704fjulia>hgheadschangeset:5:0cc37f014583branch:sauceparent:3:23cdd918e993summary:finelydiced!changeset:4:75a9cc02c946branch:sauceparent:3:23cdd918e993summary:diced!changeset:1:df75056e704fsummary:meat

julia>hgupdefault1filesupdated,0filesmerged,1filesremoved,0filesunresolvedjulia>hgmergeabort:branch'default'hasonehead-pleasemergewithanexplicitrev(run'hgheads'toseeallheads)!julia>hgupsauce2filesupdated,0filesmerged,0filesremoved,0filesunresolvedjulia>hgmergemergingsauce.txt0filesupdated,1filesmerged,0filesremoved,0filesunresolved(branchmerge,don'tforgettocommit)julia>hgcommit-m'merge'!julia>hgslog-G@|@6mergesauce5,4|\\|o|5finedicedsauce|||o||4dicedsauce|//o|3onionsauce||o|2startsauce|||o1meatdefault|/o0pizzadefault

Page 70: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Outline• Basic commands in single repository • Creating repo

• Add & edit files

• Viewing history

• Fixing last commit

• Multiple users / branches • Simple case

• Merge without conflicts

• Merge with conflicts

• Bookmarks

• Branches

• BitBucket • Fork

• Pull requests

• Final thoughts

70

Page 71: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

BitBucket• SSH key setup • View profile > BitBucket settings > SSH keys > Add key

• Creating repository • Repositories > Create Repository

• Fork • In main repo: “...” > Fork > Fork Repository

• Pull request • In forked repo: Pull requests > Create a pull request > Create

• Approving pull request • In main repo: Pull requests > select pull request > Merge

71

Page 72: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Outline• Basic commands in single repository • Creating repo

• Add & edit files

• Viewing history

• Fixing last commit

• Multiple users / branches • Simple case

• Merge without conflicts

• Merge with conflicts

• Bookmarks

• Branches

• BitBucket • Fork

• Pull requests

• Final thoughts

72

Page 73: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Hooks• Run on actions (commit, push, pull, ...)

• Run on client (under user’s control) or on server

• Can verify that action is allowed !!!!!

• Can run scripts, such as emailing notifications, posting to bugzilla, testing compilation, etc. • BitBucket handles many of these features for us

73

[hooks]#disallowtabanywhereortrailingwhitespace#runbeforecommittransactionfinishes#seehttp://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html#(herematching\tfixedusingGNU’s--perl-regexpoption)pretxncommit=hgexporttip|(!grep--perl-regexp'^\+.*(\t|$)')

.hg/hgrc

Page 74: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Other useful commands• hg outgoing # hg out

• hg incoming # hg in • Tells what commits would be pushed or pulled, respectively

• hg update --rebase • Rewrite history to avoid merge

• hg commit --interactive # or -i • Allows committing some portion of changes

74

Page 75: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Further resources• Mercurial website • https://www.mercurial-scm.org/guide • https://www.mercurial-scm.org/wiki/BeginnersGuides

• Mercurial: The Definitive Guide (2009) • Online book • http://hgbook.red-bean.com/

• hginit tutorial • http://hginit.com/

• A Guide to Branching in Mercurial (2009) • http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

75

Page 76: mercurial - ICL UTKmgates3/docs/mercurial-tutorial.pdf · Configuration • User: ~/.hgrc • Repo: .hg/hgrc • Suggested items • ~/.hgignore hides files in hg status output •

Mercurial Quick Reference• Create

hg init [dir] hg clone url [dir]

• Fileshg add files hg mv [-A] source desthg cp [-A] source desthg rm [-A] files hg revert files

• Commitshg commit [-m “message”] [--amend] [files] [--close-branch] hg pull [url] [-u] hg push [url] [-b branch | -B bookmark | -r rev] hg rollback hg outgoing [url] hg incoming [url]

• Branching & merging hg merge [rev | branch | bookmark] hg update [rev | branch | bookmark | tag] # hg up (alias hg checkout) hg update --clean . # cancel uncommitted merge hg resolve [-l | -m files] hg bookmark [--delete] [name] hg branch [name] hg brancheshg tag [-r rev] [--local] name

• Viewing changes & history hg diff [-c rev] [-r rev] [-w -b -B] [files] hg log [-l num] [-G] [--stat] [files] hg status [-acmq] [files] # hg st hg blame [-un] [files] hg heads

• Configuration files~/.hgrc # user ~/.hgignore # user, set in ~/.hgrc.hg/hgrc # repo.hgignore # repo

76