Mercurial:修改、儲存、合併
D:\hg>hg clone my-hello my-hello-new-output
updating to branch default
2 files updated, 0 files merged, 0 files removed, 0 files unresolved

D:\hg>cd my-hello-new-output

D:\hg\my-hello-new-output>

將 hello.c 的程式從下列的舊版,用編輯器改為新版。

舊版:hello.c

/*
 * 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;
}

新版:hello.c

#include <stdio.h>

int main(int argc, char **argv)
{
    printf("hello, world!\n");
    printf("how are you !\n");
    return 0;
}
D:\hg>cd my-hello-new-output

D:\hg\my-hello-new-output>hg status
M hello.c

D:\hg\my-hello-new-output>hg st
M hello.c

D:\hg\my-hello-new-output>hg diff
diff -r 82e55d328c8c hello.c
--- a/hello.c   Fri Aug 26 01:21:28 2005 -0700
+++ b/hello.c   Wed Aug 18 17:35:28 2010 +0800
@@ -1,16 +1,8 @@
-/*
- * 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");
+       printf("how are you !\n");
        return 0;
 }

D:\hg\my-hello-new-output>hg revert hello.c

D:\hg\my-hello-new-output>hg st
? hello.c.orig

D:\hg\my-hello-new-output>del hello.c

D:\hg\my-hello-new-output>ren hello.c.orig hello.c

D:\hg\my-hello-new-output>hg st
M hello.c

D:\hg\my-hello-new-output>hg ci
abort: empty commit message
HG: Enter commit message.  Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: ccc kmit <ccc@kmit.edu.tw>
HG: branch 'default'
HG: changed hello.c
D:\hg\my-hello-new-output>hg ci
abort: empty commit message
hello.c : delete comment and insert printf("how are you!");

HG: Enter commit message.  Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: ccc kmit <ccc@kmit.edu.tw>
HG: branch 'default'
HG: changed hello.c
D:\hg\my-hello-new-output>hg st

D:\hg\my-hello-new-output>hg par
changeset:   2:fa7474cb125a
tag:         tip
user:        ccc kmit <ccc@kmit.edu.tw>
date:        Wed Aug 18 17:43:32 2010 +0800
summary:     hello.c : delete comment and insert printf("how are you!");

D:\hg\my-hello-new-output>hg log
changeset:   2:fa7474cb125a
tag:         tip
user:        ccc kmit <ccc@kmit.edu.tw>
date:        Wed Aug 18 17:43:32 2010 +0800
summary:     hello.c : delete comment and insert printf("how are you!");

changeset:   1:82e55d328c8c
user:        mpm@selenic.com
date:        Fri Aug 26 01:21:28 2005 -0700
summary:     Create a makefile

changeset:   0:0a04b987be5a
user:        mpm@selenic.com
date:        Fri Aug 26 01:20:50 2005 -0700
summary:     Create a standard "hello, world" program

D:\hg\my-hello-new-output>cd ..

D:\hg>hg clone my-hello my-hello-share
updating to branch default
2 files updated, 0 files merged, 0 files removed, 0 files unresolved

D:\hg>cd my-hello-share

D:\hg\my-hello-share>hg -q tip
1:82e55d328c8c

D:\hg\my-hello-share>cd ..

D:\hg>cd my-hello-new-output

D:\hg\my-hello-new-output>hg -q tip
2:fa7474cb125a

D:\hg\my-hello-new-output>cd ../my-hello-share

D:\hg\my-hello-share>hg pull ../my-hello-new-output
pulling from ../my-hello-new-output
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
(run 'hg update' to get a working copy)

D:\hg\my-hello-share>hg up
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

D:\hg\my-hello-share>hg pull ../my-hello-new-output
pulling from ../my-hello-new-output
searching for changes
no changes found

D:\hg\my-hello-share>hg push ../my-hello-new-output
pushing to ../my-hello-new-output
searching for changes
no changes found
D:\hg\my-hello-share>hg export tip
# HG changeset patch
# User ccc kmit <ccc@kmit.edu.tw>
# Date 1282124612 -28800
# Node ID fa7474cb125a65a6c0410a627435a6aa8e981958
# Parent  82e55d328c8ca4ee16520036c0aaace03a5beb65
hello.c : delete comment and insert printf("how are you!");

diff -r 82e55d328c8c -r fa7474cb125a hello.c
--- a/hello.c   Fri Aug 26 01:21:28 2005 -0700
+++ b/hello.c   Wed Aug 18 17:43:32 2010 +0800
@@ -1,16 +1,8 @@
-/*
- * 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");
+       printf("how are you !\n");
        return 0;
 }

D:\hg\my-hello-share>cd ..

D:\hg>hg clone my-hello my-hello-desc
updating to branch default
2 files updated, 0 files merged, 0 files removed, 0 files unresolved

D:\hg>cd my-hello-desc
/*
 * 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");
    printf("Nice to meet you! \n");
    return 0;
}
D:\hg\my-hello-desc>hg commit

D:\hg\my-hello-desc>hg pull ../my-hello-new-output
pulling from ../my-hello-new-output
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)

D:\hg\my-hello-desc>hg heads
changeset:   3:fa7474cb125a
tag:         tip
parent:      1:82e55d328c8c
user:        ccc kmit <ccc@kmit.edu.tw>
date:        Wed Aug 18 17:43:32 2010 +0800
summary:     hello.c : delete comment and insert printf("how are you!");

changeset:   2:f27eee2b7c3b
user:        ccc kmit <ccc@kmit.edu.tw>
date:        Wed Aug 18 17:58:21 2010 +0800
summary:     insert printf("Nice to meet you !");

在 Mercurial.ini 當中加入下列這一行,啟動 graphlog 插件。

[extensions]
hgext.graphlog =
D:\hg\my-hello-desc>hg glog
o  changeset:   3:fa7474cb125a
|  tag:         tip
|  parent:      1:82e55d328c8c
|  user:        ccc kmit <ccc@kmit.edu.tw>
|  date:        Wed Aug 18 17:43:32 2010 +0800
|  summary:     hello.c : delete comment and insert printf("how are you!");
|
| @  changeset:   2:f27eee2b7c3b
|/   user:        ccc kmit <ccc@kmit.edu.tw>
|    date:        Wed Aug 18 17:58:21 2010 +0800
|    summary:     insert printf("Nice to meet you !");
|
o  changeset:   1:82e55d328c8c
|  user:        mpm@selenic.com
|  date:        Fri Aug 26 01:21:28 2005 -0700
|  summary:     Create a makefile
|
o  changeset:   0:0a04b987be5a
   user:        mpm@selenic.com
   date:        Fri Aug 26 01:20:50 2005 -0700
   summary:     Create a standard "hello, world" program

D:\hg\my-hello-desc>hg update
abort: crosses branches (use 'hg merge' or use 'hg update -c')

D:\hg\my-hello-desc>hg parents
changeset:   2:f27eee2b7c3b
user:        ccc kmit <ccc@kmit.edu.tw>
date:        Wed Aug 18 17:58:21 2010 +0800
summary:     insert printf("Nice to meet you !");

D:\hg\my-hello-desc>hg merge
merging hello.c
warning: conflicts during merge.
merging hello.c failed!
0 files updated, 0 files merged, 0 files removed, 1 files unresolved
use 'hg resolve' to retry unresolved file merges or 'hg update -C' to abandon
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("hello, world!\n");
<<<<<<< local
    printf("Nice to meet you! \n");
=======
    printf("how are you !\n");
>>>>>>> other
    return 0;
}
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("hello, world!\n");
    printf("Nice to meet you! \n");
    printf("how are you !\n");
    return 0;
}
D:\hg\my-hello-desc>hg resolve -m hello.c

D:\hg\my-hello-desc>hg commit
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License