Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2005-08-26 00:58:22
Size: 3906
Editor: waste
Comment:
Revision 6 as of 2005-08-26 08:27:22
Size: 3731
Editor: mpm
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== ["Tutorial"] - making our first change == == Tutorial - making our first change ==
Line 3: Line 3:
We are inside our ''my-hello'' repository that we ["Clone"]d in TutorialClone. 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 initial silly goal is to get the "hello, world" program to print another line of output. First, we ["Clone"] our {{{my-hello}}} ["Repository"].
Line 13: Line 13:
Line 24: Line 23:

The contents of ''hello.c'' look like this:
The contents of {{{hello.c}}} look like this:
Line 36: Line 34:
}}}
Line 38: Line 35:
{{{
Line 40: Line 36:
}}}
Line 42: Line 37:
{{{
Line 49: Line 43:

Let's edit ''main'' so that it prints an extra line of output:
Let's edit {{{main}}} so that it prints an extra line of output:
Line 60: Line 53:
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.
Line 61: Line 55:
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.

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.
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.
Line 66: Line 58:
 $ hg status
 C hello.c
$ hg status
M hello.c
Line 69: Line 61:
This output is terse, but it is simply telling us that {{{hello.c}}} has a change ready to go into a ChangeSet.
Line 70: Line 63:
This output is terse, but it is simply telling us that ''hello.c'' has a change ready to go into a ChangeSet.

The act of creating a ChangeSet is called ["Commit"]ting it. We perform a ["Commit"] using the ''commit'' command:
The act of creating a ChangeSet is called ["Commit"]ting it. We perform a ["Commit"] using the {{{commit}}} command:
Line 75: Line 66:
 $ hg commit $ hg commit
Line 77: Line 68:
Line 81: Line 71:
 <this line will be empty>
 HG: manifest hash 0d66196b08b861878228219d46258f088092286e
 
HG: changed hello.c
<this line will be empty>
HG: changed hello.c
Line 86: Line 75:
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 91: Line 80:
 Express great joy at existence of Mercurial Express great joy at existence of Mercurial
Line 93: Line 82:
Next, we quit the editor, and (as we're coming to expect) the {{{commit}}} command prints no output.
Line 94: Line 84:
Next, we quit the editor, and (as we're coming to expect) the ''commit'' command prints no output.

But what does the ''status'' command tell us now?
But what does the {{{status}}} command tell us now?
Line 99: Line 87:
 $ hg status $ hg status
Line 101: Line 89:
Line 105: Line 92:
 $ 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
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 112: Line 98:

Tutorial - making our first change

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 initial silly goal is to get the "hello, world" program to print another line of output. First, we ["Clone"] our my-hello ["Repository"].

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

Once again, this 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:

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

The contents of hello.c 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 vi (or our editor of choice) 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

This output is terse, but it is simply telling us that hello.c has a change ready to go into a ChangeSet.

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

$ hg commit

This will drop us into our editor, and present us with a few cryptic lines of text:

<this line will be empty>
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

Next, we quit the editor, and (as we're coming to expect) the commit command prints no output.

But what does the status command tell us now?

$ hg status

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?

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.

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)