2

SVNにマージしようとすると、ツリーの競合が山積みになります。このサンプルスクリプトの場合は1つだけですが、それでもです。

#!/bin/bash
svnadmin create repo
svn checkout file://`pwd`/repo wc
cd wc
mkdir trunk branches
svn add trunk branches
svn commit -m 'created trunk and branches'
echo red > trunk/colors
svn add trunk/colors
svn commit trunk -m 'created trunk/colors with red inside'
svn copy trunk branches/a
svn commit branches/a -m 'created branches/a'
echo green >> trunk/colors
svn commit trunk -m 'added green to trunk/colors'
echo blue >> branches/a/colors
svn commit branches/a -m 'added blue to branches/a/colors'
svn update
svn merge ^/trunk branches/a

私の結果は次のとおりです。

Checked out revision 0.
A         trunk
A         branches
Adding         branches
Adding         trunk

Committed revision 1.
A         trunk/colors
Adding         trunk/colors
Transmitting file data .
Committed revision 2.
A         branches/a
Adding         branches/a
Adding         branches/a/colors

Committed revision 3.
Sending        trunk/colors
Transmitting file data .
Committed revision 4.
Sending        branches/a/colors
Transmitting file data .
Committed revision 5.
Updating '.':
At revision 5.
--- Merging r2 through r5 into 'branches/a':
   C branches/a/colors
--- Recording mergeinfo for merge of r2 through r5 into 'branches/a':
 U   branches/a
Summary of conflicts:
  Tree conflicts: 1

SVNがマージフレンドリーであることで知られていないことは知っていますが、この場合はどういうわけか私のせいであると想定する必要があります。ポインタをありがとう。

4

3 に答える 3

9

発生した問題は、「ローカルコピー」[1]自体が原因ではありません。問題は、リビジョン3で、混合リビジョンの作業コピーをコピーするという事実にあります(http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.basic.in-action .mixedrevs)。

'trunk'を'branches/ a'にコピーするまでスクリプトを実行すると、混合リビジョンの作業コピーがあることがわかります。

>svn st -v
                 0        0  ?           .
                 1        1 pburba       branches
                 1        1 pburba       trunk
                 2        2 pburba       trunk\colors

したがって、「trunk」を「branches / a」にコピーすると、実際にはtrunk@1とtrunk/colors@2がコピーされます。

>svn copy trunk branches\a
A         branches\a

>svn st -v
                 0        0  ?           .
                 1        1 pburba       branches
A  +             -        1 pburba       branches\a
A  +             -        2 pburba       branches\a\colors
                 1        1 pburba       trunk
                 2        2 pburba       trunk\colors

>svn ci -m "Copy mixed-rev trunk"
Adding         branches\a
Adding         branches\a\colors

Committed revision 3.

r3の詳細ログを見ると、これが最も明確にわかります。

>svn log -v -r3
------------------------------------------------------------------------
r3 | pburba | 2013-03-11 15:31:23 -0400 (Mon, 11 Mar 2013) | 1 line
Changed paths:
   A /branches/a (from /trunk:1)
   A /branches/a/colors (from /trunk/colors:2)

Copy mixed-rev trunk
------------------------------------------------------------------------

問題のあるマージに進むと、混合リビジョンやローカル変更のない「クリーンな」作業コピーがあります。ここまでは順調ですね:

>svn st -v
                 5        5 pburba       .
                 5        5 pburba       branches
                 5        5 pburba       branches\a
                 5        5 pburba       branches\a\colors
                 5        4 pburba       trunk
                 5        4 pburba       trunk\colors

しかし、svn mergeinfoコマンドを使用して、マージされるリビジョンをプレビューすると、リビジョン2が適格であることがわかります。

>svn mergeinfo --show-revs eligible ^/trunk branches\a
r2
r4

しかし、待ってください、リビジョン2は「色」の追加です。

>svn log -v -r2
------------------------------------------------------------------------
r2 | pburba | 2013-03-11 15:43:52 -0400 (Mon, 11 Mar 2013) | 1 line
Changed paths:
   A /trunk/colors

created trunk/colors with red inside
------------------------------------------------------------------------

リビジョン3でブランチを作成したときに、すでにそれをコピーしました。では、なぜSubversionはそれを再びマージしようとしているのでしょうか?その理由は、私たちが作成したWCからWCへの混合リビジョンのコピーにあります。マージターゲット「branch/a」は、「trunk/colors」を追加する前にtrunk@1からコピーされたことを認識しています。したがって、マージはリビジョン2がbranch / aにマージされていないと見なし、この変更をマージしようとします。同じ名前のファイルがすでに存在する「a」に「colors」を追加すると、ツリーの競合が発生します。

>svn merge ^/trunk branches\a
--- Merging r2 through r5 into 'branches\a':
   C branches\a\colors
--- Recording mergeinfo for merge of r2 through r5 into 'branches\a':
 U   branches\a
Summary of conflicts:
  Tree conflicts: 1

>svn st
 M      branches\a
      C branches\a\colors
      >   local file obstruction, incoming file add upon merge
Summary of conflicts:
  Tree conflicts: 1

そこで、混合リビジョンのWCからWCへのコピーでSubversionをだましました。これにより、コピー中にリビジョン2がブランチに効果的にもたらされました。では、なぜSubversionはこれを検出して、リビジョン2をスキップできないのでしょうか。この場合、おそらくそれを行うことができますが、リビジョン2に「トランク」への他の変更が含まれている場合はどうなりますか?例えば:

>svn log -v -r2
------------------------------------------------------------------------
r2 | pburba | 2013-03-11 15:43:52 -0400 (Mon, 11 Mar 2013) | 1 line
Changed paths:
   A /trunk/colors
   A /trunk/README
   M /trunk

created trunk/colors with red inside, add a README file, and set the
svn:ignore property on trunk
------------------------------------------------------------------------

Subversionは、リビジョンの一部を特定のパスにマージすることをサポートしていません。オールオアナッシングのいずれかです。

~~~~~

では、この問題を回避する方法は?すでに発見したように、URLからURLへのコピーを実行すると解決します。なんで?コピーソースがURLである場合、それは定義上、一定のリビジョンであるためです。

>svn log -v -r3
------------------------------------------------------------------------
r3 | pburba | 2013-03-11 16:02:59 -0400 (Mon, 11 Mar 2013) | 1 line
Changed paths:
   A /branches/a (from /trunk:2)

Create branch 'a' from 'trunk' with a URL-to-URL copy.
------------------------------------------------------------------------

ただし、URLからWCへのコピーを使用して同じことを実行することもできます。

 svn commit trunk -m 'created trunk/colors with red inside'
-svn copy trunk branches/a
+svn copy ^/trunk branches/a
 svn commit branches/a -m 'created branches/a'

または、元のスクリプトでWCからWCにコピーする前にWCを更新するだけです。

 svn commit trunk -m 'created trunk/colors with red inside'
+svn update
 svn copy trunk branches/a
 svn commit branches/a -m 'created branches/a'

元のソリューションであるURLからURLへのコピーとそれに続く更新は、IMOの最良のオプションです。更新とWCからWCへのコピーとURLからWCへのコピーはどちらも、コミットされる前にコピーに追加の変更を加えることができる可能性を考慮に入れています。ブランチが作成されるリビジョンには、コピー以外のその他の変更。そうは言っても、これらのオプションはすべて正常に機能します[2]。

[1] Subversion-speakでは、これを通常、working-copy-to-working-copyコピー、または略してWC-to-WCコピーと呼びます。これをURLからURL、URLからWC、またはWCからURLのコピーと比較してください。WCからURLへのコピーも、上記の問題に対して脆弱です。'svncopy--help'も参照してください。

[2]もちろん、これら3つのオプションのいずれかを使用してもテキストの競合が発生しますが、ブランチの作成後にトランクとブランチの両方で「colors」ファイルに互換性のない変更を加えたため、これは予想されます。

>svn merge ^/trunk branches\a
--- Merging r3 through r5 into 'branches\a':
C    branches\a\colors
--- Recording mergeinfo for merge of r3 through r5 into 'branches\a':
 U   branches\a
Summary of conflicts:
  Text conflicts: 1
Conflict discovered in file 'branches\a\colors'.
Select: (p) postpone, (df) diff-full, (e) edit, (m) merge,
        (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: p

>svn st
 M      branches\a
C       branches\a\colors
?       branches\a\colors.merge-left.r2
?       branches\a\colors.merge-right.r5
?       branches\a\colors.working
Summary of conflicts:
  Text conflicts: 1
于 2013-03-11T20:48:56.407 に答える
1

svn copy問題は、リモートではなくローカルの使用にあるようです。

-svn copy trunk branches/a
-svn commit branches/a -m 'created branches/a'
+svn copy ^/trunk ^/branches/a -m 'server side copy from trunk to branches/a'
+svn update

SVNの本には、ローカルコピーは「テクニックは推奨されない」と書かれていますが、これは理由として記載されていません。むしろ、それは単に安価なサーバー側のコピー、ディスク使用量、時間などについて話します。

于 2013-02-21T16:07:01.257 に答える
0

示したケースでは、通常の競合が発生するはずですが、ツリーの競合が発生することはありません。

ユースケースがサブツリーマージを実行していると思われます(svn mergeコマンドのサブツリーパスに注意してください)。すべてのmergeinfoのものは、チェックアウトのトップレベルにのみ保存されます

'svn help merge'から:

 SOURCE specifies the branch from where the changes will be pulled, and
 TARGET_WCPATH specifies a working copy of the target branch to which
 the changes will be applied. Normally SOURCE and TARGET_WCPATH should
 each correspond to the root of a branch. (If you want to merge only a
 subtree, then the subtree path must be included in both SOURCE and
 TARGET_WCPATH; this is discouraged, to avoid subtree mergeinfo.)

次のスニペットは、サブツリーのマージを回避しながら、探していると思われる機能を示しています。'svn switch'を使用して、サブツリーのマージと複数のWCを回避します

export SVN_REPO=~/svntest
cd $SVN_REPO
rm -rf $SVN_REPO/*
svnadmin create repo
svn mkdir file:///$SVN_REPO/repo/trunk -m "created trunk"
svn mkdir file:///$SVN_REPO/repo/branches -m "created branches"
#
svn checkout file:///$SVN_REPO/repo/trunk wc
cd wc
echo red > colors
svn add colors
svn commit . -m 'created trunk/colors with red inside' 
#
svn cp file:///$SVN_REPO/repo/trunk file:///$SVN_REPO/repo/branches/a  -m 'created branches/a'
#
echo green >> colors
svn commit . -m 'added green to trunk/colors'
#
svn switch file:///$SVN_REPO/repo/branches/a .
echo blue >> colors
svn commit  -m 'added blue to branches/a/colors'
svn update
svn merge file:///$SVN_REPO/repo/trunk

結果:

Committed revision 1.
SVN_REPO/repo/branches -m "created branches"

Committed revision 2.

SVN_REPO/repo/trunk wc
Checked out revision 2.
 cd wc
 echo red > colors
 svn add colors
 A         colors
 svn commit . -m 'created trunk/colors with red inside'
Adding         colors
Transmitting file data .
Committed revision 3.

SVN_REPO/repo/branches/a  -m 'created branches/a'

Committed revision 4.

 echo green >> colors
 svn commit . -m 'added green to trunk/colors'
Sending        colors
Transmitting file data .
Committed revision 5.

SVN_REPO/repo/branches/a .
 U    colors
Updated to revision 5.
 echo blue >> colors
 svn commit  -m 'added blue to branches/a/colors'
Sending        colors
Transmitting file data .
Committed revision 6.
 svn update
Updating '.':
At revision 6.

Conflict discovered in '/home/jbellamy/svntest/wc/colors'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
--- Merging r4 through r6 into '.':
 C    colors
--- Recording mergeinfo for merge of r4 through r6 into '.':
 U   .
Summary of conflicts:
  Text conflicts: 1
     svn diff
Index: .
===================================================================
--- .   (revision 6)
+++ .   (working copy)

Property changes on: .
___________________________________________________________________
Added: svn:mergeinfo
   Merged /trunk:r4-6
Index: colors
===================================================================
--- colors      (revision 6)
+++ colors      (working copy)
@@ -1,2 +1,6 @@
 red
+<<<<<<< .working
 blue
+=======
+green
+>>>>>>> .merge-right.r6
于 2013-02-21T16:24:38.657 に答える