Differences between revisions 5 and 9 (spanning 4 versions)
Revision 5 as of 2005-08-26 01:36:56
Size: 3882
Editor: waste
Comment:
Revision 9 as of 2005-09-30 03:57:37
Size: 5281
Editor: TKSoh
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
We are inside our {{{my-hello}}} repository that we ["Clone"]d in TutorialClone. Carrying forward from TutorialHistory, we are inside our {{{my-hello}}} repository that we ["Clone"]d in TutorialClone.
Line 7: Line 7:
Our initial silly goal is to get the "hello, world" program to print another line of output. First, we ["Clone"] our {{{my-hello}}} ["Repository"]. Our silly goal is to get the "hello, world" program to print another line of output. First, we create a new repository called {{{my-hello-new-output}}}, by cloning from {{{my-hello}}}, for our little project.
Line 10: Line 10:
 $ cd ..
 $ hg clone my-hello my-hello-new-output
$ cd ..
$ hg clone my-hello my-hello-new-output
Line 13: Line 13:
Once again, this command prints no output if it succeeds.
Line 15: Line 14:
'''Note''': Notice that we have given our new ["Repository"] a descriptive name, basically identifying the purpose of the ["Repository"]. Since making a ["Clone"] of a ["Repository"] in ["Mercurial"] is cheap, we will quickly accumulate many slightly different repositories. If we do not give these repositories descriptive names, we will rapidly lose the ability to tell them apart. In this case, the clone command prints no output if it succeeds.
Line 17: Line 16:
Now it's time to make a change in the new repository. Let's go into the WorkingDirectory, which is simply our name for the directory where all the files are: '''Note:''' Notice that we have given our new ["Repository"] a descriptive name, basically identifying the purpose of the ["Repository"]. Since making a ["Clone"] of a ["Repository"] in ["Mercurial"] is cheap, we will quickly accumulate many slightly different repositories. If we do not give these repositories descriptive names, we will rapidly lose the ability to tell them apart.

Now it's time to make a change in the new repository. Let's go into the WorkingDirectory, which is simply our name for the directory where all the files are, and modify the source code with our favorite editor:
Line 20: Line 21:
 $ cd my-hello-new-output
 $ vi hello.c
$ cd my-hello-new-output
$ vi hello.c
Line 23: Line 24:
The contents of {{{hello.c}}} look like this:
Line 25: Line 25:
{{{
 /*
  * hello.c
  *
  * Placed in the public domain by Bryan O'Sullivan
  *
  * This program is not covered by patents in the United States or other
  * countries.
  */
The contents of {{{hello.c}}} initially look like this:
Line 35: Line 27:
 #include <stdio.h> {{{#!cplusplus numbers=off
/*
 * hello.c
 *
 * Placed in the public domain by Bryan O'Sullivan
 *
 * This program is not covered by patents in the United States or other
 * countries.
 */
Line 37: Line 37:
 int main(int argc, char **argv)
 {
     printf("hello, world!\n");
     return 0;
 }
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("hello, world!\n");
        return 0;
}
Line 43: Line 45:
Line 45: Line 48:
{{{
 int main(int argc, char **argv)
 {
     printf("hello, world!\n");
     printf("sure am glad I'm using Mercurial!\n");
     return 0;
 }
{{{#!cplusplus numbers=off
(...)

int main(int argc, char **argv)
{
    printf("hello, world!\n");
    printf("sure am glad I'm using Mercurial!\n");
        return 0;
}
Line 53: Line 58:
Once we're done, we quit out of {{{vi}}} (or our editor of choice) and we're done. That's it. The edit is now ready for us to create a ChangeSet.
Once we're done, we quit out of our favorite editor, and we're done. That's it. The edit is now ready for us to create a ChangeSet.
Line 58: Line 64:
 $ hg status
 C hello.c
$ hg status
M hello.c
Line 61: Line 67:
This output is terse, but it is simply telling us that {{{hello.c}}} has a change ready to go into a ChangeSet.
The output is terse, but prefix {{{M}}} is simply telling us that {{{hello.c}}} has been modified, so our change is ready to go into a ChangeSet.

We may also examine the actual changes we have made to the file using the {{{diff}}} command:

{{{
$ hg diff
diff -r 82e55d328c8c hello.c
--- a/hello.c Fri Aug 26 01:21:28 2005 -0700
+++ b/hello.c Fri Sep 30 10:27:47 2005 +0800
@@ -12,5 +12,6 @@
 int main(int argc, char **argv)
 {
        printf("hello, world!\n");
+ printf("sure am glad I'm using Mercurial!\n");
        return 0;
 }
}}}

<!> In case we wish to '''discard''' our changes and start over, we may use the {{{revert}}} command to restore the files to their unmodified state. Just make sure you know this is what you really want.

{{{
$ hg revert
}}}
Line 66: Line 95:
 $ hg commit $ hg commit
Line 68: Line 97:
This will drop us into our editor, and present us with a few cryptic lines of text:
This drops us into an editor, and presents us with a few cryptic lines of text.

'''Note:''' The default editor is {{{vi}}}. This can be changed using the {{{EDITOR}}} or {{{HGEDITOR}}} environment variables. Also, the manifest hash might be different, depending on how you typed and saved the file.
Line 71: Line 103:
 <this line will be empty>
 HG: manifest hash 0d66196b08b861878228219d46258f088092286e
 HG: changed hello.c
(empty line)
HG: manifest hash 14595beb70bcfb74bf227437d70c38878421c944
HG: changed hello.c
Line 75: Line 107:
The first line is empty, the second contains a big long hash, and the lines that follow identify the files that will go into this ChangeSet.
The first line is empty and the lines that follow identify the files that will go into this ChangeSet.
Line 80: Line 113:
 Express great joy at existence of Mercurial Express great joy at existence of Mercurial
HG: manifest hash 14595beb70bcfb74bf227437d70c38878421c944
HG: changed hello.c
Line 82: Line 117:
Next, we quit the editor, and (as we're coming to expect) the {{{commit}}} command prints no output.
Line 84: Line 118:
But what does the {{{status}}} command tell us now? Next, we save the test and quit the editor, and, if all goes well, the {{{commit}}} command will exit and prints no output. <!> If you quit the editor without saving the text, {{{commit}}} will abort the operation, so you may change your mind before committing.

Let's see what the {{{status}}} command will tell us now?
Line 87: Line 123:
 $ hg status $ hg status
Line 89: Line 125:
Nothing! Our change has been ["Commit"]ted to a ChangeSet, so our ["Tip"] now matches our working directory contents. Does that mean our new commit will show up in the change history?
Line 91: Line 126:
Nothing! Our change has been ["Commit"]ted to a ChangeSet, so there's no modified file in need of a commit. Our ["Tip"] now matches our working directory contents.

We can now examine the the change history for our new work:
Line 92: Line 130:
 $ hg log
 changeset: 3:da99cce05957f7a62b74d345fd55365dc33109f0
 tag: tip
 user: bos@camp4.serpentine.com
 date: Wed Jun 29 12:58:37 2005
 summary: Express great joy at existence of Mercurial
$ hg log
changeset: 2:a58809af174d
tag: tip
user: mpm@selenic.com
date: Fri Aug 26 01:26:28 2005 -0700
summary: Express great joy at existence of Mercurial

(...)
Line 99: Line 139:
Line 100: Line 141:

'''Note:''' The user, date, and ChangeSetID will of course vary.

Tutorial - making our first change

Carrying forward from TutorialHistory, we are inside our my-hello repository that we ["Clone"]d in TutorialClone.

It is good ["Mercurial"] development practice to isolate each change in a separate ["Repository"]. This prevents unrelated code from getting mixed up, and makes it easier to test individual chunks of work one by one. Let's start out by following that model.

Our silly goal is to get the "hello, world" program to print another line of output. First, we create a new repository called my-hello-new-output, by cloning from my-hello, for our little project.

$ cd ..
$ hg clone my-hello my-hello-new-output

In this case, the clone command prints no output if it succeeds.

Note: Notice that we have given our new ["Repository"] a descriptive name, basically identifying the purpose of the ["Repository"]. Since making a ["Clone"] of a ["Repository"] in ["Mercurial"] is cheap, we will quickly accumulate many slightly different repositories. If we do not give these repositories descriptive names, we will rapidly lose the ability to tell them apart.

Now it's time to make a change in the new repository. Let's go into the WorkingDirectory, which is simply our name for the directory where all the files are, and modify the source code with our favorite editor:

$ cd my-hello-new-output
$ vi hello.c

The contents of hello.c initially look like this:

/*
 * hello.c
 *
 * Placed in the public domain by Bryan O'Sullivan
 *
 * This program is not covered by patents in the United States or other
 * countries.
 */

#include <stdio.h>

int main(int argc, char **argv)
{
        printf("hello, world!\n");
        return 0;
}

Let's edit main so that it prints an extra line of output:

(...)

int main(int argc, char **argv)
{
        printf("hello, world!\n");
        printf("sure am glad I'm using Mercurial!\n");
        return 0;
}

Once we're done, we quit out of our favorite editor, and we're done. That's it. The edit is now ready for us to create a ChangeSet.

But what if we're been interrupted, and we've forgotten what changes are going to make it into the ChangeSet once we create it? For this, we use the status command.

$ hg status
M hello.c

The output is terse, but prefix M is simply telling us that hello.c has been modified, so our change is ready to go into a ChangeSet.

We may also examine the actual changes we have made to the file using the diff command:

$ hg diff
diff -r 82e55d328c8c hello.c
--- a/hello.c   Fri Aug 26 01:21:28 2005 -0700
+++ b/hello.c   Fri Sep 30 10:27:47 2005 +0800
@@ -12,5 +12,6 @@
 int main(int argc, char **argv)
 {
        printf("hello, world!\n");
+       printf("sure am glad I'm using Mercurial!\n");
        return 0;
 }

<!> In case we wish to discard our changes and start over, we may use the revert command to restore the files to their unmodified state. Just make sure you know this is what you really want.

$ hg revert

The act of creating a ChangeSet is called ["Commit"]ting it. We perform a ["Commit"] using the commit command:

$ hg commit

This drops us into an editor, and presents us with a few cryptic lines of text.

Note: The default editor is vi. This can be changed using the EDITOR or HGEDITOR environment variables. Also, the manifest hash might be different, depending on how you typed and saved the file.

(empty line)
HG: manifest hash 14595beb70bcfb74bf227437d70c38878421c944
HG: changed hello.c

The first line is empty and the lines that follow identify the files that will go into this ChangeSet.

To ["Commit"] the ChangeSet, we must describe the reason for it. This is usually called a ChangeSet comment. Let's type something like this:

Express great joy at existence of Mercurial
HG: manifest hash 14595beb70bcfb74bf227437d70c38878421c944
HG: changed hello.c

Next, we save the test and quit the editor, and, if all goes well, the commit command will exit and prints no output. <!> If you quit the editor without saving the text, commit will abort the operation, so you may change your mind before committing.

Let's see what the status command will tell us now?

$ hg status

Nothing! Our change has been ["Commit"]ted to a ChangeSet, so there's no modified file in need of a commit. Our ["Tip"] now matches our working directory contents.

We can now examine the the change history for our new work:

$ hg log
changeset:   2:a58809af174d
tag:         tip
user:        mpm@selenic.com
date:        Fri Aug 26 01:26:28 2005 -0700
summary:     Express great joy at existence of Mercurial

(...)

There it is! We've ["Commit"]ted a ChangeSet.

Note: The user, date, and ChangeSetID will of course vary.

As we discussed in TutorialClone, the new ChangeSet only exists in this repository. This is a critical part of the way ["Mercurial"] works.

To share changes, we must continue to TutorialShareChange.

TutorialFirstChange (last edited 2013-02-23 03:48:44 by mpm)