Size: 5215
Comment:
|
Size: 5531
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
#language zh |
|
Line 3: | Line 5: |
完成了[:TutorialHistory:教程-历史] 的学习之后, 我们来到 {{{my-hello}}} [仓库]里面,就是我们在 [:TutorialClone:教程-克隆]中 [克隆] 得到的。 | 完成了[[ChineseTutorialHistory|教程-历史]] 的学习之后, 我们来到 {{{my-hello}}} [仓库]里面,就是我们在 [[ChineseTutorialClone|教程-克隆]]中 [克隆] 得到的。 |
Line 5: | Line 7: |
在 ["Mercurial"] 开发实践中一个好的做法是把每个变更隔离在各自的[:Repository:仓库]里。这样可以避免把不相关的代码混杂起来, 并且便于一个接一个的测试每一部分工作。我们现在就开始采用这一模式。 | 在 [[Mercurial]] 开发实践中一个好的做法是把每个变更隔离在各自的[[Repository|仓库]]里。这样可以避免把不相关的代码混杂起来, 并且便于一个接一个的测试每一部分工作。我们现在就开始采用这一模式。 |
Line 14: | Line 16: |
这一次, 克隆命令如果成功将不会打印任何输出。 | updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
Line 16: | Line 19: |
'''注:''' 注意我们给新的 [:Repository:仓库] 命名了一个描述性 的名字,基本上是说明这个[:Repository:仓库]的目的。 在["Mercurial"]里面给一个[:Repository:仓库]创建[克隆]很方便,我们会很快的积攒起很多稍微不同的仓库。如果我们不给他们描述性的命名, 很快就会没法分辨它们。 | '''注:''' 注意我们给新的 [[Repository|仓库]] 命名了一个描述性 的名字,基本上是说明这个[[Repository|仓库]]的目的。 在[[Mercurial]]里面给一个[[Repository|仓库]]创建[克隆]很方便,我们会很快的积攒起很多稍微不同的仓库。如果我们不给他们描述性的命名, 很快就会没法分辨它们。 |
Line 18: | Line 21: |
现在可以在新的仓库里面进行修改了 。 我们进入[:WorkingDirectory:工作目录],使用我们喜欢的编辑软件修改源文件。 | 现在可以在新的仓库里面进行修改了 。 我们进入[[WorkingDirectory|工作目录]],使用我们喜欢的编辑软件修改源文件。 |
Line 22: | Line 25: |
$ vi hello.c }}} |
|
Line 25: | Line 26: |
{{{hello.c}}} 的内容原来是: {{{#!cplusplus numbers=off /* * hello.c * |
|
Line 61: | Line 56: |
可是万一我们背别的事情打扰,在创建变更集之后忘记了它里面有哪些变更,怎么办呢? 这时候我们要用到{{{status}}}命令。 | 可是万一我们被别的事情打扰,在创建变更集之后忘记了它里面有哪些变更,怎么办呢? 这时候我们要用到{{{status}}}命令。 |
Line 87: | Line 82: |
<!> 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. | <!> 万一我们希望'''放弃'''我们的变更并重新开始,我们可以用{{{revert}}}命令来恢复到我们没有更改的状态。请确认你确实知道这是你真的希望做的。 |
Line 92: | Line 87: |
root@bt:/data0/my_hello_new_output# hg revert 中止: no files or directories specified; use --all to revert the whole repo root@bt:/data0/my_hello_new_output# hg revert --all 正在恢复 hello.c |
|
Line 93: | Line 92: |
The act of creating a ChangeSet is called ["Commit"]ting it. We perform a ["Commit"] using the {{{commit}}} command: | 创建一个变更集的动作称为[[Commit|提交]]它。我们用{{{commit}}}命令来执行[[Commit|提交]]。 |
Line 99: | Line 98: |
This drops us into an editor, and presents us with a few cryptic lines of text. | 这个命令把我们带到一个编辑器内,同时给我们展示了几行语焉不详的文字。 |
Line 101: | Line 100: |
'''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. | '''注:''' 缺省的编辑器是{{{vi}}}。这可以用环境变量{{{EDITOR}}} 或 {{{HGEDITOR}}} 来改变。同样,根据你怎样输入和保存文件,变更集记录哈希表可能不一样。 |
Line 109: | Line 108: |
The first line is empty and the lines that follow identify the files that will go into this ChangeSet. | 第一行是空的,接下来的几行标明哪些文件将进入本变更集。T |
Line 111: | Line 110: |
To ["Commit"] the ChangeSet, we must describe the reason for it. This is usually called a ChangeSet comment. Let's type something like this: | 为了[[Commit|提交]]变更集,我们必须描述它的原因。这通常称为变更集注释。让我们输入一些: |
Line 119: | Line 118: |
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. | 接着,我保存测试并退出编辑器,如果一切正常,{{{commit}}}命令将没有任何提示地退出。 <!> 如果你在没有保存文本的情况下退出编辑器,{{{commit}}} 将中断操作,这样你可以在提交前改变你的想法。 |
Line 121: | Line 120: |
Let's see what the {{{status}}} command will tell us now? | 让我们看看{{{status}}}命令现在告诉我们什么? |
Line 127: | 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. | 什么也没有!我们的变更已经[[Commit|提交]]到变更集里了,那里没有修改的文件需要提交的。我们的[[Tip|末端]]现在和我们工作目录的内容一致了。 |
Line 129: | Line 128: |
We can now examine the change history for our new work: | 我们现在可以为我们的新工作检查变更的历史: |
Line 141: | Line 140: |
There it is! We've ["Commit"]ted a ChangeSet. | 就是它了!我们已经[[Commit|提交]]了一个变更集。 |
Line 143: | Line 142: |
'''Note:''' The user, date, and ChangeSetID will of course vary. | '''注:''' 用户,日期和[[ChangeSetID|变更集号]]当然和我的是不一样的。 |
Line 145: | Line 144: |
As we discussed in TutorialClone, the new ChangeSet only exists in this repository. This is a critical part of the way ["Mercurial"] works. | 正如我们在[[ChineseTutorialClone|教程--复制]]中讨论的,新的[[ChangeSet|变更集]]只存在于本仓库中。 这是[[Mercurial]]关键的一部分工作方法。 |
Line 147: | Line 146: |
To share changes, we must continue to ChineseTutorialShareChange. | 如果要分享变更,我们必须继续[[ChineseTutorialShareChange|教程 - 与别的仓库分享改变]]。 ---- CategoryChinese |
教程 - 生成第一个[变更]
完成了教程-历史 的学习之后, 我们来到 my-hello [仓库]里面,就是我们在 教程-克隆中 [克隆] 得到的。
在 Mercurial 开发实践中一个好的做法是把每个变更隔离在各自的仓库里。这样可以避免把不相关的代码混杂起来, 并且便于一个接一个的测试每一部分工作。我们现在就开始采用这一模式。
我们的目标很简单,让“hello, world”程序打印另外一行输出。 首先, 我们给这个小项目创建一个新的仓库叫做 my-hello-new-output,方法是对my-hello做克隆。
$ cd .. $ hg clone my-hello my-hello-new-output
updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
注: 注意我们给新的 仓库 命名了一个描述性 的名字,基本上是说明这个仓库的目的。 在Mercurial里面给一个仓库创建[克隆]很方便,我们会很快的积攒起很多稍微不同的仓库。如果我们不给他们描述性的命名, 很快就会没法分辨它们。
现在可以在新的仓库里面进行修改了 。 我们进入工作目录,使用我们喜欢的编辑软件修改源文件。
$ cd my-hello-new-output * 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; }
我们要修改 main 让它再多打印一行输出:
(...)
int main(int argc, char **argv)
{
printf("hello, world!\n");
printf("sure am glad I'm using Mercurial!\n");
return 0;
}
完成之后退出我们喜欢的编辑器,任务完成。 有了刚才的修改我们就可以创建一个[变更集]。
可是万一我们被别的事情打扰,在创建变更集之后忘记了它里面有哪些变更,怎么办呢? 这时候我们要用到status命令。
$ hg status M hello.c
输出很简短。总之以 M 开头的行意思就是hello.c文件修改过了,那么我们的变更已经可以加入一个变更集了。
使用 diff 命令我们可以检查文件实际的改变:
$ 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; }
万一我们希望放弃我们的变更并重新开始,我们可以用revert命令来恢复到我们没有更改的状态。请确认你确实知道这是你真的希望做的。
$ hg revert
root@bt:/data0/my_hello_new_output# hg revert 中止: no files or directories specified; use --all to revert the whole repo root@bt:/data0/my_hello_new_output# hg revert --all 正在恢复 hello.c
创建一个变更集的动作称为提交它。我们用commit命令来执行提交。
$ hg commit
这个命令把我们带到一个编辑器内,同时给我们展示了几行语焉不详的文字。
注: 缺省的编辑器是vi。这可以用环境变量EDITOR 或 HGEDITOR 来改变。同样,根据你怎样输入和保存文件,变更集记录哈希表可能不一样。
(empty line) HG: manifest hash 14595beb70bcfb74bf227437d70c38878421c944 HG: changed hello.c
第一行是空的,接下来的几行标明哪些文件将进入本变更集。T
为了提交变更集,我们必须描述它的原因。这通常称为变更集注释。让我们输入一些:
Express great joy at existence of Mercurial HG: manifest hash 14595beb70bcfb74bf227437d70c38878421c944 HG: changed hello.c
接着,我保存测试并退出编辑器,如果一切正常,commit命令将没有任何提示地退出。 如果你在没有保存文本的情况下退出编辑器,commit 将中断操作,这样你可以在提交前改变你的想法。
让我们看看status命令现在告诉我们什么?
$ hg status
什么也没有!我们的变更已经提交到变更集里了,那里没有修改的文件需要提交的。我们的末端现在和我们工作目录的内容一致了。
我们现在可以为我们的新工作检查变更的历史:
$ 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 (...)
就是它了!我们已经提交了一个变更集。
注: 用户,日期和变更集号当然和我的是不一样的。
正如我们在教程--复制中讨论的,新的变更集只存在于本仓库中。 这是Mercurial关键的一部分工作方法。
如果要分享变更,我们必须继续教程 - 与别的仓库分享改变。