为什么这个Subversion合并会导致树冲突而不是合并冲突?

时间:2014-11-26 10:04:52

标签: svn tree-conflict

问题

我原本预计文件a.txt会发生合并冲突,因为第2行在trunkbranch/featurex同时发生了变化。

  1. 为什么我会遇到树冲突而不是合并冲突?
  2. 如何显示冲突? svn diff
  3. 如何解决此冲突?
  4. 重现情况的示例

    要重现树冲突,您可以对trunkbranches/featurex进行更改,并尝试将trunk合并到branches/featurex

    创建分支:

    PS C:\> mkdir demo
    PS C:\> cd demo
    PS C:\demo> svnadmin create svnrepo
    PS C:\demo> cd workspace
    PS C:\demo\workspace> mkdir trunk
    PS C:\demo\workspace> mkdir branches
    PS C:\demo\workspace> mkdir tags
    PS C:\demo\workspace> svn add trunk
    PS C:\demo\workspace> svn add branches
    PS C:\demo\workspace> svn add tags
    PS C:\demo\workspace> svn ci -m "Create SVN default folders"
    PS C:\demo\workspace> cd trunk
    PS C:\demo\workspace\trunk> echo "trunk: line1" > a.txt
    PS C:\demo\workspace\trunk> svn add .\a.txt
    PS C:\demo\workspace\trunk> svn ci -m "1st commit on trunk"
    PS C:\demo\workspace\trunk> svn copy . ..\branches\featurex
    PS C:\demo\workspace\trunk> cd ..
    PS C:\demo\workspace> cd .\branches
    PS C:\demo\workspace\branches> svn ci -m "Create branch for feature x"
    Adding         featurex
    Adding  (bin)  featurex\a.txt
    

    在trunk上提交更改:

    PS C:\demo\workspace\trunk> echo "trunk: line2" >> .\a.txt
    PS C:\demo\workspace\trunk> svn ci -m "2nd commit on trunk"
    

    在分支上提交更改(在同一行上创建合并冲突):

    PS C:\demo\workspace\branches\featurex> svn up
    PS C:\demo\workspace\branches\featurex> echo "branch: line2" >> .\a.txt
    PS C:\demo\workspace\branches\featurex> svn ci -m "1st commit on branch"
    

    将主干合并到分支:

    PS C:\demo\workspace\branches\featurex> svn up
    PS C:\demo\workspace\branches\featurex> svn merge file:///c:/demo/svnrepo/trunk
    --- Merging r2 through r5 into '.':
       C a.txt
    --- Recording mergeinfo for merge of r2 through r5 into '.':
     U   .
    Summary of conflicts:
      Tree conflicts: 1
    PS C:\demo\workspace\branches\featurex>
    

    它是:意外的树冲突。

    a.txt的内容并未显示与合并冲突的任何合并,它只显示"分支版本"有了这个内容:

    trunk: line1
    branch: line2
    

    版本

    Subversion版本1.7.8(r1419691)编译于2012年12月12日,21:11:09

1 个答案:

答案 0 :(得分:0)

PS C:\demo\workspace\trunk> svn copy . ..\branches\featurex
PS C:\demo\workspace\trunk> cd ..
PS C:\demo\workspace> cd .\branches
PS C:\demo\workspace\branches> svn ci -m "Create branch for feature x"

创建分支的正确方法,如

这样的事实所证明
Adding         featurex
Adding  (bin)  featurex\a.txt

没有提到它们是副本。要使它们复制,源必须是存储库URL(并且目标也应该是)。尝试使用以下方法创建分支:

PS C:\demo\workspace\trunk> svn copy -m "Create branch for feature x" "^/trunk" "^/branches/featurex"

(当您在工作副本中时,^是存储库根目录的别名)后跟svn update。或者更确切地说svn switch - 除了在一次提交而不是三次提交中创建初始结构之外,你不应该检查多个分支!