0

Mercurial の複数のファイルをすべてのブランチで一度にあるディレクトリから別のディレクトリに移動する方法を見つけようとしています。アイデアは、ディレクトリにいくつかのファイルがあるということです

a/some_file

に移動する必要があります

b/a/some_file

しかし、ブランチ構造でこれを行います

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

ノード 9 の一部のファイルはすでに変更されていますが、1 つ上のディレクトリに移動する必要があることに注意してください。また、両方のブランチに存在するように、ノード 7 にいくつかのファイルを追加したいと思います。しかし、重要なことはファイルを移動することです。

4

1 に答える 1

1

名前の変更はマージ全体に伝播するため、チェンジセット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'

次に、他の2つのブランチをフォークbr.8br.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)を使用でき、このチェンジセットをすべての上位ブランチにマージすることもできます。それでも各ブランチを個別に実行する必要がありますが、名前が変更されたもの、名前が変更されたのは誰か、いつ発生したか、いつ派生ブランチにマージされたかなど、すべてを追跡できるというアイデアが気に入っています

于 2013-01-09T23:07:38.253 に答える