在mercurial中的几个分支中移动文件

时间:2013-01-09 10:32:38

标签: mercurial

我正在尝试找出如何将mercurial中的多个文件一次从一个目录移动到另一个目录中的另一个目录。 我的想法是我在目录中有一些文件

A / SOME_FILE

应移至

B / A / SOME_FILE

但在branchstructure中执行此操作

 10   9
 |    |
 |    8
 |    |
 |____/
 7
 |
 ...

要记住,节点9中的某些文件已经更改,但也应该向上移动一个目录。 此外,我想在节点7添加一些文件,以便它们存在于两个分支中。但重要的是移动文件。

1 个答案:

答案 0 :(得分:1)

重命名在合并中传播,因此如果您在变更集7中签出文件,将其重命名为那里,然后将重命名更改合并到其余分支,Mercurial应该做正确的事。< / p>

例如,请参阅以下命令跟踪中发生的情况。我首先创建一个测试库:

saturn:/tmp$ hg init test
saturn:/tmp$ cd test

然后,我确保一个名为&#39; foo.txt&#39;的文件。存在于名为br.7的分支上的toplevel目录中:

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'

然后我从'br.7&#39;的最新变更集中分叉另外两个分支br.8br.9。分支:

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-style 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

请注意重命名看起来像真正的实际合并&#39;现在进行操作,看看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

这样,您可以在最旧的位置使用一个更改集(在此示例中为changeset d57b57b98f19),并且您可以将此更改集合并到所有上层分支。你仍然需要单独完成每个分支,但我喜欢能够跟踪所有内容的想法:重命名的内容,重命名的人,发生的时间以及合并时的到衍生分支。

相关问题