Commits

Anonymous committed da52d60

added example output for all basic workflows except sharing changes.

  • Participants
  • Parent commits fcec523

Comments (0)

Files changed (2)

+#!/bin/sh
+
+# Example script which shows the actions in the workflow guide.
+
+
+# make sure , project does not exist before starting.
+rm -r project feature1
+
+# plain output
+export HGPLAIN=1
+
+echo init, add and commit
+
+hg init project
+cd project
+echo "[ui]" >> .hg/hgrc
+echo "username = Mr. Johnson <johnson@smith.com>" >> .hg/hgrc
+echo 'print("Hello")' > hello.py
+hg add
+#hg commit
+hg commit --date "2011-11-20 11:00" -m "Initial commit."
+
+echo status
+
+echo 'print("Hello World")' > hello.py
+hg status
+hg diff
+#hg commit
+hg commit --date "2011-11-20 11:11" -m "Say Hello World, not just Hello."
+
+echo move and copy
+
+hg cp hello.py copy
+hg mv hello.py target
+hg status
+hg diff
+hg ci --date "2011-11-20 11:20" -m "Copy and move."
+
+echo log
+hg log
+
+echo Lone developer with nonlinear history
+
+hg update 1
+hg identify -n
+
+echo 'print("Hello Mercurial")' > hello.py
+hg ci --date "2011-11-20 20:00" -m "Greet Mercurial"
+hg merge
+hg ci --date "2011-11-20 20:11" -m "merge greeting and copy+move."
+
+hg log
+
+cd ..
+hg clone project feature1
+cd feature1
+hg update 3
+echo 'print("Hello feature1")' > hello.py
+hg commit --date "2011-11-20 20:11:11" -m "Greet feature1"
+cd ../project
+hg in ../feature1
+hg pull ../feature1
+hg merge
+hg commit --date "2011-11-20 20:20" -m "merged feature1"
+hg log -r -1:-3
+hg rollback
+hg commit --date "2011-11-20 20:20" -m "Merged Feature 1"
+hg log -r -1:-2
 
 <h5>Add files and track them</h5>
 
+<p>Enter the project folder, create some files, then add and commit them.</p>
+
 <pre>$ cd project
-$ (add files)
+$ echo 'print("Hello")' > hello.py
 $ hg add
 $ hg commit
 (enter the commit message)
 
 </pre>
 
+<div class="output">output of hg add:
+adding hello.py
+</div>
+
+<div class="output">output of hg commit (with your message):
+Initial commit.
+
+HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+HG: Leave message empty to abort commit.
+HG: --
+HG: user: Mr. Johnson &lt;johnson@smith.com&gt;
+HG: branch 'default'
+HG: added hello.py
+</div>
+
 <div class="note">
 <p class="note-title">Note:</p>
 You can also go into an existing directory with files and init the repository there.
 
 <h5>Save changes</h5>
 
-<pre>$ (do some changes)
+<p>First do some changes:</p>
+
+<pre>$ echo 'print("Hello World") > hello.py
 
 </pre>
 
 
 </pre>
 
+<div class="output">output of hg status:
+M hello.py
+</div>
+
+
 <p>see the exact changes</p>
 
 <pre>$ hg diff
 
 </pre>
 
+<div class="output">output of hg diff:
+diff --git a/hello.py b/hello.py
+--- a/hello.py
++++ b/hello.py
+@@ -1,1 +1,1 @@
+-print("Hello")
++print("Hello World")
+</div>
+
+
 <p><em>commit</em> the changes.</p>
 
 <pre>$ hg commit
 
 <p>now an editor pops up and asks you for a commit message. Upon saving and closing the editor, your changes have been stored by Mercurial.</p>
 
+<div class="output">output of hg commit (with your message):
+Say Hello World, not just Hello.
+
+HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+HG: Leave message empty to abort commit.
+HG: --
+HG: user: Mr. Johnson &lt;johnson@smith.com&gt;
+HG: branch 'default'
+HG: changed hello.py
+</div>
+
 <div class="note">
 <p class="note-title">Note:</p>
 You can also supply the commit message directly via <em>hg commit -m 'MESSAGE'</em>.
 </div>
 
-<h5>Move and copy files</h5>
+<h5>Copy and move files</h5>
 
 <p>When you copy or move files, you should tell Mercurial to do the copy or move for you, so it can track the relationship between the files.</p>
 
 <p>Remember to <em>commit</em> after moving or copying. From the basic commands only <em>commit</em> creates a new revision</p>
 
-<pre>$ hg cp original copy
-$ hg commit
-(enter the commit message)
-$ hg mv original target
+<pre>$ hg cp hello.py copy
+$ hg mv hello.py target
+$ hg diff # see the changes
 $ hg commit
 (enter the commit message)
 
 
 <p>Now you have two files, "copy" and "target", and Mercurial knows how they are related.</p>
 
+<div class="output">output of hg diff (before the commit): 
+diff --git a/hello.py b/copy
+rename from hello.py
+rename to copy
+diff --git a/hello.py b/target
+copy from hello.py
+copy to target
+</div>
+
 <div class="note">
 <p class="note-title">Note:</p>
 Should you forget to do the explicit copy or move, you can still tell Mercurial to detect the changes via <em>hg addremove --similarity 100</em>. Just use <em>hg help addremove</em> for details.
 
 <p>This prints a list of changesets along with their date, the user who committed them (you) and their commit message. </p>
 
+<div class="output">output of hg log:
+changeset:   2:70eb0ca9d264
+tag:         tip
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 11:20:00 2011 +0100
+summary:     Copy and move.
+
+changeset:   1:487d7a20ccbc
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 11:11:00 2011 +0100
+summary:     Say Hello World, not just Hello.
+
+changeset:   0:a5ecbf5799c8
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 11:00:00 2011 +0100
+summary:     Initial commit.
+</div>
+
 <p>To see a certain revision, you can use the <em>-r</em> switch (--revision). To also see the diff of the displayed revisions, there's the <em>-p</em> switch (--patch)</p>
 
 <pre>$ hg log -p -r 3
 
 <p>Different from the log keeping workflow, you'll want to go back in history at times and do some changes directly there, for example because an earlier change introduced a bug and you want to fix it where it occurred.</p>
 
-<p>To look at a previous version of your code, you can use update. Let's assume that you want to see revision 3.</p>
+<p>To look at a previous version of your code, you can use update. Let's assume that you want to see revision 1.</p>
 
-<pre>$ hg update 3
+<pre>$ hg update 1
 
 </pre>
 
-<p>Now your code is back at revision 3, the fourth commit (Mercurial starts counting at 0).
+<p>Now your code is back at revision 1, the second commit (Mercurial starts counting at 0).
 To check if you're really at that revision, you can use <em>identify -n</em>.</p>
 
 <pre>$ hg identify -n
 
 </pre>
 
+<div class="output">output of hg identify -n:
+1
+</div>
+
+<div class="output">output of ls: 
+hello.py
+</div>
+
+
 <div class="note">
 <p class="note-title">Note:</p>
 <em>identify</em> without options gives you the short form of a unique revision ID. That ID is what Mercurial uses internally. If you tell someone about the version you updated to, you should use that ID, since the numbers can be different for other people. If you want to know the reasons behind that, please read up Mercurials [<a href="http://mercurial.selenic.com/wiki/UnderstandingMercurial">basic concepts</a>]. When you're at the most recent revision, <em>hg identify -n</em> will return "-1".
 To get a revision devoid of files, just <em>update</em> to "null" via <em>hg update null</em>. That's the revision before any files were added.
 </div>
 
+<div class="note">
+<p class="note-title">Note:</p>
+If the output of <em>hg identify</em> ends in a “+”, your repository has uncommitted changes.
+</div>
+
+
 <h5>Fixing errors in earlier revisions</h5>
 
 <p>When you find a bug in some earlier revision you have two options: either you can fix it in the current code, or you can go back in history and fix the code exactly where you did it, which creates a cleaner history.</p>
 
 <p>To do it the cleaner way, you first update to the old revision, fix the bug and commit it. Afterwards you merge this revision and commit the merge. Don't worry, though: Merging in mercurial is fast and painless, as you'll see in an instant.</p>
 
-<p>Let's assume the bug was introduced in revision 3.</p>
+<p>Let's assume the bug was introduced in revision 1.</p>
 
-<pre>$ hg update 3
-$ (fix the bug)
+<pre>$ hg update 1
+$ echo 'print("Hello Mercurial")' > hello.py
 $ hg commit
 
 </pre>
 
+<div class="output">output of hg commit (after entering the message):
+created new head
+</div>
+
+<div class="note">
+<p class="note-title">Note:</p>
+“created new head” means that there is now one more revision, which does not have children. Heads are current states of your project living side by side. It is good style to merge them together before propagating them.
+</div>
+
+
 <p>Now the fix is already stored in history. We just need to merge it with the current version of your code.</p>
 
 <pre>$ hg merge
 
 </pre>
 
+<div class="output">output of hg merge (here):
+merging hello.py and copy to copy
+merging hello.py and target to target
+</div>
+
 <p>If there are conflicts use <em>hg resolve</em> - that's also what merge tells you to do in case of conflicts.</p>
 
 <p>First list the files with conflicts</p>
 
 <p>At this point, your fix is merged with all your other work, and you can just go on coding. Additionally the history shows clearly where you fixed the bug, so you'll always be able to check where the bug was.</p>
 
+<div class="output">output of hg log (after the final commit):
+changeset:   4:3b06bba7c1a9
+tag:         tip
+parent:      3:7ff5cd572d80
+parent:      2:70eb0ca9d264
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 20:11:00 2011 +0100
+summary:     merge greeting and copy+move.
+
+changeset:   3:7ff5cd572d80
+parent:      1:487d7a20ccbc
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 20:00:00 2011 +0100
+summary:     Greet Mercurial
+
+changeset:   2:70eb0ca9d264
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 11:20:00 2011 +0100
+summary:     Copy and move.
+
+changeset:   1:487d7a20ccbc
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 11:11:00 2011 +0100
+summary:     Say Hello World, not just Hello.
+
+changeset:   0:a5ecbf5799c8
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 11:00:00 2011 +0100
+summary:     Initial commit.
+</div>
+
+
 <div class="note">
 <p class="note-title">Note:</p>
 Most merges will just work. You only need <em>resolve</em>, when <em>merge</em> complains.
 
 <pre>$ hg clone project feature1
 $ cd feature1
-$ (do some changes and commits)
+$ hg update 3
+$ echo 'print("Hello feature1")' > hello.py
+$ hg commit -m "Greet feature1"
 
 </pre>
 
 
 </pre>
 
+<div class="output">output of hg incoming ../feature1:
+comparing with ../feature1
+searching for changes
+changeset:   5:3eb7b39fcf57
+tag:         tip
+parent:      3:7ff5cd572d80
+user:        Arne Babenhauserheide <bab@draketo.de>
+date:        Sun Nov 20 20:11:11 2011 +0100
+summary:     Greet feature1
+</div>
+
+
 <div class="note">
 <p class="note-title">Note:</p>
 If you want to see the diffs, you can use <em>hg incoming --patch</em> just as you can do with <em>hg log --patch</em> for the changes in the repository.
 
 <p>Now you have the history of feature1 inside your project, but the changes aren't yet visible. Instead they are only stored inside a ".hg" directory of the project (<a title="Behind the Scenes" href="http://hgbook.red-bean.com/read/behind-the-scenes.html">more information on the store</a>).</p>
 
+<div class="output">output of hg pull:
+pulling from ../feature1
+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)
+</div>
+
 <div class="note">
 <p class="note-title">Note:</p>
 From now on we'll use the name "repository" for a directory which has a .hg directory with Mercurial history.
 
 </pre>
 
+<div class="output">output of hg log -r -1:-3 (the last 3 changesets):
+changeset:   6:e8a33691171a
+tag:         tip
+parent:      4:3b06bba7c1a9
+parent:      5:3eb7b39fcf57
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 20:20:00 2011 +0100
+summary:     merged feature1
+
+changeset:   5:3eb7b39fcf57
+parent:      3:7ff5cd572d80
+user:        Arne Babenhauserheide <bab@draketo.de>
+date:        Sun Nov 20 20:11:11 2011 +0100
+summary:     Greet feature1
+
+changeset:   4:3b06bba7c1a9
+parent:      3:7ff5cd572d80
+parent:      2:70eb0ca9d264
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 20:11:00 2011 +0100
+summary:     merge greeting and copy+move.
+</div>
+
+
+<div class="note">
+<p class="note-title">Note:</p>
+Mercurial offers powerful ways specify revisions. Too see them all, use <em>hg help revsets</em>.
+</div>
+
+
 <p>You can create an arbitrary number of clones and also carry them around on USB sticks. Also you can use them to synchronize your files at home and at work, or between your desktop and your laptop.</p>
 
 <div class="note">
 
 <p>Rolling back means undoing the last operation which added something to your history.</p>
 
-<p>Imagine you just realized that you did a bad commit - for example you didn't see a spelling error in a label. To fix it you would use</p>
+<p>Imagine you just realized that you did a bad commit - for example you didn't see a spelling error in a commit message. To fix it you would use</p>
 
 <pre>$ hg rollback
 
 
 <p>And then redo the commit</p>
 
-<pre>$ hg commit -m "message"
+<pre>$ hg commit -m "Merged Feature 1"
 
 </pre>
 
+<div class="output">output of hg rollback:
+repository tip rolled back to revision 5 (undo commit)
+working directory now based on revisions 4 and 5
+</div>
+
+<div class="output">output of hg log -r -1:-2 (after rollback and commit):
+changeset:   6:e9a5787e476e
+tag:         tip
+parent:      4:3b06bba7c1a9
+parent:      5:3eb7b39fcf57
+user:        Mr. Johnson <johnson@smith.com>
+date:        Sun Nov 20 20:20:00 2011 +0100
+summary:     Merged Feature 1
+
+changeset:   5:3eb7b39fcf57
+parent:      3:7ff5cd572d80
+user:        Arne Babenhauserheide <bab@draketo.de>
+date:        Sun Nov 20 20:11:11 2011 +0100
+summary:     Greet feature1
+</div>
+
+
+
 <p>If you can use the command history of your shell and you added the previous message via <em>commit -m "message"</em>, that following commit just means two clicks on the arrow-key "up" and one click on "enter".</p>
 
 <p>Though it changes your history, rolling back doesn't change your files. It only undoes the last addition to your history.</p>