我试图找出如何一次将 mercurial 中的多个文件从一个目录移动到所有分支中的另一个目录。这个想法是我在一个目录中有一些文件
一个/一些文件
应该移到
b/a/some_file
但在分支结构中执行此操作
10 9
| |
| 8
| |
|____/
7
|
...
要记住的是节点 9 中的一些文件已经更改,但也应该向上移动一个目录。另外我想在节点 7 处添加一些文件,以便它们存在于两个分支中。但重要的是移动文件。
我试图找出如何一次将 mercurial 中的多个文件从一个目录移动到所有分支中的另一个目录。这个想法是我在一个目录中有一些文件
一个/一些文件
应该移到
b/a/some_file
但在分支结构中执行此操作
10 9
| |
| 8
| |
|____/
7
|
...
要记住的是节点 9 中的一些文件已经更改,但也应该向上移动一个目录。另外我想在节点 7 处添加一些文件,以便它们存在于两个分支中。但重要的是移动文件。
重命名会在合并中传播,因此如果您检查变更集 7 处的文件,在那里重命名它们,然后将重命名更改合并到其余分支,Mercurial 应该做正确的事情。
例如,请参阅以下命令跟踪中发生的情况。我首先创建一个测试存储库:
saturn:/tmp$ hg init test
saturn:/tmp$ cd test
然后,我确保一个名为“foo.txt”的文件存在于一个名为的分支的顶层目录中br.7
:
saturn:/tmp/test$ echo foo > foo.txt
saturn:/tmp/test$ hg commit -Am 'add foo'
adding foo.txt
saturn:/tmp/test$ hg branch br.7
marked working directory as branch br.7
(branches are permanent and global, did you want a bookmark?)
saturn:/tmp/test$ hg commit -m 'br.7 opened'
然后我 fork 其他两个分支,br.8
并br.9
从 `br.7' 分支的最新变更集中:
saturn:/tmp/test$ hg up -C br.7
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
saturn:/tmp/test$ hg branch br.8
marked working directory as branch br.8
(branches are permanent and global, did you want a bookmark?)
saturn:/tmp/test$ hg commit -m 'br.8 opened'
saturn:/tmp/test$ hg up -C br.7
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
saturn:/tmp/test$ hg branch br.9
marked working directory as branch br.9
(branches are permanent and global, did you want a bookmark?)
saturn:/tmp/test$ hg commit -m 'br.9 opened'
现在变更集图如下所示:
saturn:/tmp/test$ hg log --graph --style=compact
@ 3[tip]:1 f3f155b61aa8 2013-01-09 23:48 +0100 gkeramidas
| br.9 opened
|
| o 2 ad3b03105da7 2013-01-09 23:48 +0100 gkeramidas
|/ br.8 opened
|
o 1 9cfed898c77b 2013-01-09 23:48 +0100 gkeramidas
| br.7 opened
|
o 0 9a6f15da68d7 2013-01-09 23:47 +0100 gkeramidas
add foo
因此,如果我尝试先重命名分支中的文件,br.7
然后向上合并重命名,则会发生以下情况:
saturn:/tmp/test$ hg up -C br.7
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
saturn:/tmp/test$ mkdir subdir
saturn:/tmp/test$ hg rename foo.txt subdir/foo.txt
saturn:/tmp/test$ hg commit -m 'Rename foo.txt'
saturn:/tmp/test$ hg branches
br.7 4:d57b57b98f19
br.9 3:f3f155b61aa8
br.8 2:ad3b03105da7
default 0:9a6f15da68d7 (inactive)
然后,最后,我将重命名变更集从分支合并br.7
到更高的分支:
saturn:/tmp/test$ hg up -C br.8
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
saturn:/tmp/test$ hg merge br.7
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
(branch merge, don't forget to commit)
合并的结果在 git 风格的 diff 输出中如下所示:
saturn:/tmp/test$ hg diff --git
diff --git a/foo.txt b/foo.txt
deleted file mode 100644
--- a/foo.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-foo
diff --git a/subdir/foo.txt b/subdir/foo.txt
--- /dev/null
+++ b/subdir/foo.txt
@@ -0,0 +1,1 @@
+foo
如果我提交此更改,则历史现在如下所示:
saturn:/tmp/test$ hg log --graph --style=compact
@ 5[tip]:2,4 22b095e35b43 2013-01-10 00:02 +0100 gkeramidas
|\ Merge rename of foo.txt
| |
| o 4:1 d57b57b98f19 2013-01-09 23:49 +0100 gkeramidas
| | Rename foo.txt
| |
| | o 3:1 f3f155b61aa8 2013-01-09 23:48 +0100 gkeramidas
| |/ br.9 opened
| |
o | 2 ad3b03105da7 2013-01-09 23:48 +0100 gkeramidas
|/ br.8 opened
|
o 1 9cfed898c77b 2013-01-09 23:48 +0100 gkeramidas
| br.7 opened
|
o 0 9a6f15da68d7 2013-01-09 23:47 +0100 gkeramidas
add foo
注意重命名现在看起来像一个真正的“合并”操作,并查看 log --copies 如何通过重命名操作返回到foo.txt
在此输出中添加的原始更改:
saturn:/tmp/test$ hg log --copies --style=compact foo.txt subdir/foo.txt
4:1 d57b57b98f19 2013-01-09 23:49 +0100 gkeramidas
Rename foo.txt
0 9a6f15da68d7 2013-01-09 23:47 +0100 gkeramidas
add foo
这样,您可以拥有一个变更集(本示例中的变更集 d57b57b98f19)在最旧的可能位置执行重命名操作,并且您也可以将此变更集合并到所有上层分支。您仍然需要单独执行每个分支,但我喜欢能够跟踪所有内容的想法:重命名的内容,重命名的人,发生的时间以及合并到派生分支的时间。