这是一个非常简化的工作流程,假设两个补丁不重叠,即两个补丁不修改相同的文件。
$ hg init myrepo
$ cd myrepo
$ echo "This is file1" >file1
$ echo "This is file2" >file2
$ hg add
adding file1
adding file2
$ hg commit -m 'initial files'
# Initialize and work on patch1
$ hg qnew -m 'Fix for bug1' patch1
$ echo "a second line" >>file1
$ hg diff
diff --git a/file1 b/file1
--- a/file1
+++ b/file1
@@ -1,1 +1,1 @@
-This is file1
+a second line
$ hg qdiff
diff --git a/file1 b/file1
--- a/file1
+++ b/file1
@@ -1,1 +1,1 @@
-This is file1
+a second line
# Update the current patch (patch1)
$ hg qrefresh
$ hg diff
$ hg qdiff
diff --git a/file1 b/file1
--- a/file1
+++ b/file1
@@ -1,1 +1,1 @@
-This is file1
+a second line
# Initialize and work on patch2
$ hg qnew -m 'Fix for bug2' patch2
$ hg qseries
patch1
patch2
$ hg qtop
patch2
$ hg diff
$ echo 'another line for file2' >>file2
$ hg diff
diff --git a/file2 b/file2
--- a/file2
+++ b/file2
@@ -1,1 +1,2 @@
This is file2
+another line for file2
$ hg qrefresh
$ hg diff
$ hg qdiff
diff --git a/file2 b/file2
--- a/file2
+++ b/file2
@@ -1,1 +1,2 @@
This is file2
+another line for file2
# Export patch2
$ hg export qtip
# HG changeset patch
# User My Name <myemail>
# Date 1362771912 28800
# Node ID 2baa2bf81b000d4d720f9c4151242458b90bcd80
# Parent ccd75363c8f459bec4a8d6b94dfb4150fb9e3014
Fix for bug2
diff --git a/file2 b/file2
--- a/file2
+++ b/file2
@@ -1,1 +1,2 @@
This is file2
+another line for file2
# Pop back to and export patch1
$ hg qpop
popping patch2
now at: patch1
$ hg export qtip
# HG changeset patch
# User My Name <myemail>
# Date 1362771745 28800
# Node ID ccd75363c8f459bec4a8d6b94dfb4150fb9e3014
# Parent a227e9c42f2d17fb28082ad2451a03d4926505ba
Fix for bug1
diff --git a/file1 b/file1
--- a/file1
+++ b/file1
@@ -1,1 +1,1 @@
-This is file1
+a second line
# Resume working on patch2
$ hg qpush
applying patch2
now at: patch2
...
# Apply patch1 to repo
$ hg qpop
popping patch2
now at: patch1
$ hg qfinish -a
$ hg qseries
patch2
$ hg summary
parent: 1:ccd75363c8f4 tip
Fix for bug1
branch: default
commit: (clean)
update: (current)
mq: 1 unapplied
$ hg qpush
applying patch2
now at: patch2
请记住,Mercurial 队列旨在管理有序的补丁列表,其中系列中的后续补丁可能会修改早期补丁所做的更改。如果您正在处理的项目涉及对同一组文件进行并行开发,那么 MQ 可能不是最好的工具。在这种情况下,请考虑使用带有或不带有书签的 Mercurial 分支或 Mercurial 匿名头像。