我在主干中有一个特性分支,并定期将主干中的更改合并到分支中,一切都运行正常。今天,我将分支合并回主干中,在创建分支后添加到主干中的任何文件都被标记为“树冲突”。将来有办法避免这种情况吗?

我认为他们没有被正确标记。


当前回答

I came across this problem today as well, though my particular issue probably isn't related to yours. After inspecting the list of files, I realized what I had done -- I had temporarily been using a file in one assembly from another assembly. I have made lots of changes to it and didn't want to orphan the SVN history, so in my branch I had moved the file over from the other assembly's folder. This isn't tracked by SVN, so it just looks like the file is deleted and then re-added. This ends up causing a tree conflict.

我通过将文件移回,提交,然后合并我的分支来解决这个问题。然后我把文件移了回来。:)这似乎奏效了。

其他回答

我不知道这是否发生在你身上,但有时我选择了错误的目录合并,我得到这个错误,即使所有的文件看起来完全正常。

例子:

合并/ svn /项目/部门/分公司/来源 to /svn/Project/trunk——>树冲突

合并/ svn /项目/部门/分公司 to /svn/Project/trunk——> OK

这可能是一个愚蠢的错误,但它并不总是显而易见的,因为你认为它是更复杂的东西。

I came across this problem today as well, though my particular issue probably isn't related to yours. After inspecting the list of files, I realized what I had done -- I had temporarily been using a file in one assembly from another assembly. I have made lots of changes to it and didn't want to orphan the SVN history, so in my branch I had moved the file over from the other assembly's folder. This isn't tracked by SVN, so it just looks like the file is deleted and then re-added. This ends up causing a tree conflict.

我通过将文件移回,提交,然后合并我的分支来解决这个问题。然后我把文件移了回来。:)这似乎奏效了。

我有时会遇到这样的情况:

假设您有一个主干,从中创建了一个发布分支。在主干上做了一些更改之后(特别是创建“some-dir”目录),你创建了一个特性/修复分支,你想稍后将其合并到发布分支中(因为更改足够小,而且特性/修复对于发布非常重要)。

trunk -- ... -- create "some-dir" -- ...
     \                                  \-feature/fix branch
      \- release branch

如果你尝试将特性/修复分支直接合并到发布分支中,你会得到一个树冲突(即使目录甚至不存在于特性/修复分支中):

svn status
!     C some-dir
      >   local missing or deleted or moved away, incoming file edit upon merge

因此,在创建feature/fix分支之前,你需要显式地合并在trunk上完成的提交,该分支在合并feature/fix分支之前创建了“some-dir”目录。

我经常忘记这一点,因为这在git中是不必要的。

这里发生的事情如下:在主干上创建一个新文件,然后将它合并到分支中。在合并提交中,这个文件也将在分支中创建。

当您将分支合并回中继中时,SVN再次尝试做同样的事情:它看到分支中创建了一个文件,并试图在合并提交中在中继中创建它,但它已经存在!这就产生了树冲突。

避免这种情况的方法,是做一个特殊的合并,重新整合。您可以使用——reintegrate开关来实现这一点。

你可以在文档中读到: http://svnbook.red-bean.com/en/1.7/svn.branchmerge.basicmerging.html#svn.branchemerge.basicmerging.reintegrate

When merging your branch back to the trunk, however, the underlying mathematics are quite different. Your feature branch is now a mishmash of both duplicated trunk changes and private branch changes, so there's no simple contiguous range of revisions to copy over. By specifying the --reintegrate option, you're asking Subversion to carefully replicate only those changes unique to your branch. (And in fact, it does this by comparing the latest trunk tree with the latest branch tree: the resulting difference is exactly your branch changes!)

在重新集成一个分支之后,非常明智的做法是将其移除,否则当您从另一个方向(从主干到分支)合并时,您将继续得到树冲突。(原因与之前描述的完全相同。)

其实也有办法,但我从没试过。你可以在这篇文章中阅读:v1.6中的Subversion分支重新整合

Subversion 1.6添加了树冲突来覆盖目录级别的冲突。一个很好的例子是,当您在本地删除一个文件时,更新会尝试对该文件进行文本更改。另一种情况是,当您对正在编辑的文件进行subversion重命名时,因为这是一个添加/删除操作。

CollabNet的Subversion博客上有一篇关于树冲突的很棒的文章。