SVN如何解决“本地添加,更新时传入添加”问题在*文件夹*上?

发布于 2024-09-28 20:30:47 字数 3426 浏览 7 评论 0原文

这是我的场景:

假设我们有一个包含以下内容的 SVN 存储库: 我的文件夹 myfolder\file.txt

现在我创建此存储库的两个签出:co1 和 co2。

在co1中我们修改file.txt。 在 co2 中,我们:

  • svn delete myfolder
  • svn commit
  • 创建一个名为 myfolder 的新文件夹
  • svn add myfolder
  • svn commit

现在,如果我尝试在 co1 中进行更新,则会出现树冲突:

A  +  C myfolder >   local edit, incoming delete upon update
M  +    myfolder\file.txt

我想保留 myfolder 和修改后的文件,因此我解决了树冲突:

svn resolve --accept working folder

现在,如果我尝试提交,我会收到“svn:目录'/myfolder'已过期”。如果我尝试使用 svn up myfolder 解决此问题,我会再次遇到树冲突:

A  +  C folder >   local add, incoming add upon update
M  +    myfolder\file.txt

好的,所以我们再次尝试 svn resolve --accept 工作文件夹。但我们仍然无法提交,我们收到相同的消息“svn:目录'/ myfolder'已过期”,如果我们执行svn up myfolder,我们会立即回到最后一个树冲突。

解决此类冲突的正确步骤是什么(当我们希望保留 myfolder 及其更改时)?

编辑:Windows cmd 行脚本来说明:

rmdir /S /Q C:\svntest 
mkdir C:\svntest

cd C:\svntest

svnadmin create repo

svn co file:///c:/svntest/repo co1
svn co file:///c:/svntest/repo co2

cd co1
mkdir folder
echo content > folder\file.txt
svn add folder
svn commit folder -m ""

cd C:\svntest\co2
svn up

cd C:\svntest\co1
svn del folder
svn commit -m ""
mkdir folder
svn add folder
svn commit -m ""

cd C:\svntest\co2
echo changed_content > folder\file.txt
svn up
svn resolve --accept working folder
svn commit -m ""

svn up folder
svn resolve --accept working folder
svn commit -m ""

这是运行该脚本的输出(请注意最后的提交失败):

C:\>rmdir /S /Q C:\svntest  

C:\>mkdir C:\svntest 

C:\>cd C:\svntest 

C:\svntest>svnadmin create repo 

C:\svntest>svn co file:///c:/svntest/repo co1 
Checked out revision 0.

C:\svntest>svn co file:///c:/svntest/repo co2 
Checked out revision 0.

C:\svntest>cd co1 

C:\svntest\co1>mkdir folder 

C:\svntest\co1>echo content  1>folder\file.txt 

C:\svntest\co1>svn add folder 
A         folder
A         folder\file.txt

C:\svntest\co1>svn commit folder -m "" 
Adding         folder
Adding         folder\file.txt
Transmitting file data .
Committed revision 1.

C:\svntest\co1>cd C:\svntest\co2 

C:\svntest\co2>svn up 
A    folder
A    folder\file.txt
Updated to revision 1.

C:\svntest\co2>cd C:\svntest\co1 

C:\svntest\co1>svn del folder 
D         folder\file.txt
D         folder

C:\svntest\co1>svn commit -m "" 
Deleting       folder

Committed revision 2.

C:\svntest\co1>mkdir folder 

C:\svntest\co1>svn add folder 
A         folder

C:\svntest\co1>svn commit -m "" 
Adding         folder

Committed revision 3.

C:\svntest\co1>cd C:\svntest\co2 

C:\svntest\co2>echo changed_content  1>folder\file.txt 

C:\svntest\co2>svn up 
C folder
At revision 3.
Summary of conflicts:
  Tree conflicts: 1

C:\svntest\co2>svn resolve --accept working folder 
Resolved conflicted state of 'folder'

C:\svntest\co2>svn commit -m "" 
Adding         folder
svn: Commit failed (details follow):
svn: Directory '/folder' is out of date

C:\svntest\co2>svn up folder 
   C folder
At revision 3.
Summary of conflicts:
  Tree conflicts: 1

C:\svntest\co2>svn resolve --accept working folder 
Resolved conflicted state of 'folder'

C:\svntest\co2>svn commit -m "" 
Adding         folder
svn: Commit failed (details follow):
svn: Directory '/folder' is out of date

Here is my scenario:

Assume we have an SVN repo with the following content:
myfolder
myfolder\file.txt

Now I create two checkouts of this repo, co1 and co2.

In co1 we modify file.txt.
In co2 we:

  • svn delete myfolder
  • svn commit
  • Create a new folder named myfolder
  • svn add myfolder
  • svn commit

Now if I attempt an update in co1 I get a tree conflict:

A  +  C myfolder >   local edit, incoming delete upon update
M  +    myfolder\file.txt

I want to keep myfolder and the modified file, so I resolve the tree conflict:

svn resolve --accept working folder

Now if I try to commit, I get "svn: Directory '/myfolder' is out of date". If I try to resolve this using svn up myfolder, I get a tree conflict again:

A  +  C folder >   local add, incoming add upon update
M  +    myfolder\file.txt

Okay, so we try svn resolve --accept working folder again. But we still can't commit, we get the same message that "svn: Directory '/myfolder' is out of date", if we do svn up myfolder, we get right back to the last tree conflict.

What is the correct procedure to resolve this type of conflict (when we wish to keep myfolder and its changes)?

EDIT: Windows cmd line script to illustrate:

rmdir /S /Q C:\svntest 
mkdir C:\svntest

cd C:\svntest

svnadmin create repo

svn co file:///c:/svntest/repo co1
svn co file:///c:/svntest/repo co2

cd co1
mkdir folder
echo content > folder\file.txt
svn add folder
svn commit folder -m ""

cd C:\svntest\co2
svn up

cd C:\svntest\co1
svn del folder
svn commit -m ""
mkdir folder
svn add folder
svn commit -m ""

cd C:\svntest\co2
echo changed_content > folder\file.txt
svn up
svn resolve --accept working folder
svn commit -m ""

svn up folder
svn resolve --accept working folder
svn commit -m ""

And here is the output of running that script (note the commit failures at the end):

C:\>rmdir /S /Q C:\svntest  

C:\>mkdir C:\svntest 

C:\>cd C:\svntest 

C:\svntest>svnadmin create repo 

C:\svntest>svn co file:///c:/svntest/repo co1 
Checked out revision 0.

C:\svntest>svn co file:///c:/svntest/repo co2 
Checked out revision 0.

C:\svntest>cd co1 

C:\svntest\co1>mkdir folder 

C:\svntest\co1>echo content  1>folder\file.txt 

C:\svntest\co1>svn add folder 
A         folder
A         folder\file.txt

C:\svntest\co1>svn commit folder -m "" 
Adding         folder
Adding         folder\file.txt
Transmitting file data .
Committed revision 1.

C:\svntest\co1>cd C:\svntest\co2 

C:\svntest\co2>svn up 
A    folder
A    folder\file.txt
Updated to revision 1.

C:\svntest\co2>cd C:\svntest\co1 

C:\svntest\co1>svn del folder 
D         folder\file.txt
D         folder

C:\svntest\co1>svn commit -m "" 
Deleting       folder

Committed revision 2.

C:\svntest\co1>mkdir folder 

C:\svntest\co1>svn add folder 
A         folder

C:\svntest\co1>svn commit -m "" 
Adding         folder

Committed revision 3.

C:\svntest\co1>cd C:\svntest\co2 

C:\svntest\co2>echo changed_content  1>folder\file.txt 

C:\svntest\co2>svn up 
C folder
At revision 3.
Summary of conflicts:
  Tree conflicts: 1

C:\svntest\co2>svn resolve --accept working folder 
Resolved conflicted state of 'folder'

C:\svntest\co2>svn commit -m "" 
Adding         folder
svn: Commit failed (details follow):
svn: Directory '/folder' is out of date

C:\svntest\co2>svn up folder 
   C folder
At revision 3.
Summary of conflicts:
  Tree conflicts: 1

C:\svntest\co2>svn resolve --accept working folder 
Resolved conflicted state of 'folder'

C:\svntest\co2>svn commit -m "" 
Adding         folder
svn: Commit failed (details follow):
svn: Directory '/folder' is out of date

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

说谎友 2024-10-05 20:30:47

我弄清楚了

svn resolve --accept working  PATH_TO_FILE

最终应该是:

解决了“PATH_TO_FILE”的冲突状态

I figured out with

svn resolve --accept working  PATH_TO_FILE

which should end up with:

Resolved conflicted state of 'PATH_TO_FILE'

残花月 2024-10-05 20:30:47

树冲突很好地概述了树冲突及其解决。在某些情况下,svn revert 也可能有所帮助,但会丢失所有本地修改。作为最后的手段,一个新的工作副本,其中手动合并了“损坏的”工作副本中的更改,将使您回到正轨。绝对是颠覆的阴暗面。

Tree Conflicts gives a nice overview of tree conflicts and their resolution. In some cases svn revert might help as well, while loosing all your local modifications. As last resort a new working copy with manually merged changes from the 'broken' one will bring you back on track. Definitely the dark side of subversion.

风为裳 2024-10-05 20:30:47

尝试

C:\svntest\co2>move folder folder.SAVE
C:\svntest\co2>svn revert folder
C:\svntest\co2>svn update

Svn 后应该会引入一个与 co1 中的版本相同的新 folder 目录版本。然后,您可以使用 folder.SAVE 中的内容进行覆盖。

Try

C:\svntest\co2>move folder folder.SAVE
C:\svntest\co2>svn revert folder
C:\svntest\co2>svn update

Svn should then bring in a fresh folder directory version identical with the one from co1. You can then overwrite with the content from folder.SAVE.

深府石板幽径 2024-10-05 20:30:47

我无法重现您提到的内容。这是我尝试过的。

test@test:/tmp$ cd /tmp/ 
test@test:/tmp$ svn co http://localhost:8080/svn/stackoverflow so --username=admin
A    so/trunk
A    so/branches
A    so/tags
Checked out revision 1.
test@test:/tmp$ cd so/trunk/ 
test@test:/tmp/so/trunk$ mkdir x 
test@test:/tmp/so/trunk$ ls /tmp > x/test.txt 
test@test:/tmp/so/trunk$ svn add x/ 
A         x
A         x/test.txt
test@test:/tmp/so/trunk$ svn ci -m "test"
Adding         trunk/x
Adding         trunk/x/test.txt
Transmitting file data .
Committed revision 2.
test@test:/tmp/so/trunk$ cd /tmp/ 
test@test:/tmp$ svn co http://localhost:8080/svn/stackoverflow so1 --username=admin 
A    so1/trunk
A    so1/trunk/x
A    so1/trunk/x/test.txt
A    so1/branches
A    so1/tags
Checked out revision 2.
test@test:/tmp$ cd /tmp/so1/trunk/ 
test@test:/tmp/so1/trunk$ svn remove x 
D         x/test.txt
D         x
test@test:/tmp/so1/trunk$ svn ci -m "" 
Deleting       trunk/x

Committed revision 3.
test@test:/tmp/so1/trunk$ mkdir x 
test@test:/tmp/so1/trunk$ cp ../../so/trunk/x/test.txt x 
test@test:/tmp/so1/trunk$ ll /tmp > x/test.txt 
test@test:/tmp/so1/trunk$ svn add x/ 
A         x
A         x/test.txt
test@test:/tmp/so1/trunk$ svn ci -m ""
Adding         trunk/x
Adding         trunk/x/test.txt
Transmitting file data .
Committed revision 4.
test@test:/tmp$ cd so/trunk/
test@test:/tmp/so/trunk$ svn up
D    x
A    x
A    x/test.txt
Updated to revision 4.
test@test:/tmp/so/trunk$ 

显然我尝试了与您相同的方法,并且没有再次遇到任何问题。你使用什么版本的 svn ?

export REPOPATH=/tmp/svntest
test@test:/tmp/co2/trunk$ rm -rf $REPOPATH
test@test:/tmp/co2/trunk$ mkdir $REPOPATH
test@test:/tmp/co2/trunk$ svnadmin create $REPOPATH/repo
test@test:/tmp/co2/trunk$ svn co file:///$REPOPATH/repo co1
svn: Repository UUID '2d803eb8-2030-4dd3-bb6f-34ab07c74813' doesn't match expected UUID '82764ae8-6410-4565-933f-9a420cb60013'
test@test:/tmp/co2/trunk$ svn co file:///$REPOPATH/repo co2
svn: Repository UUID '2d803eb8-2030-4dd3-bb6f-34ab07c74813' doesn't match expected UUID '82764ae8-6410-4565-933f-9a420cb60013'
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co1
bash: cd: /tmp/svntest/co1: No such file or directory
test@test:/tmp/co2/trunk$ mkdir folder
mkdir: cannot create directory `folder': File exists
test@test:/tmp/co2/trunk$ echo content > folder/file.txt
test@test:/tmp/co2/trunk$ svn add folder
svn: warning: 'folder' is already under version control
test@test:/tmp/co2/trunk$ svn commit folder -m ""
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co2
bash: cd: /tmp/svntest/co2: No such file or directory
test@test:/tmp/co2/trunk$ svn up
At revision 10.
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co1
bash: cd: /tmp/svntest/co1: No such file or directory
test@test:/tmp/co2/trunk$ svn del folder
svn: Use --force to override this restriction
svn: 'folder/file.txt' is not under version control
test@test:/tmp/co2/trunk$ svn commit -m ""
test@test:/tmp/co2/trunk$ mkdir folder
mkdir: cannot create directory `folder': File exists
test@test:/tmp/co2/trunk$ svn add folder
svn: warning: 'folder' is already under version control
test@test:/tmp/co2/trunk$ svn commit -m ""
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co2
bash: cd: /tmp/svntest/co2: No such file or directory
test@test:/tmp/co2/trunk$ echo changed_content > folder\file.txt
test@test:/tmp/co2/trunk$ svn up
At revision 10.
test@test:/tmp/co2/trunk$ svn --version
svn, version 1.6.6 (r40053)
   compiled Dec 12 2009, 05:04:54

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme

I am not able reproduce what you have mentioned. Here is what I have tried.

test@test:/tmp$ cd /tmp/ 
test@test:/tmp$ svn co http://localhost:8080/svn/stackoverflow so --username=admin
A    so/trunk
A    so/branches
A    so/tags
Checked out revision 1.
test@test:/tmp$ cd so/trunk/ 
test@test:/tmp/so/trunk$ mkdir x 
test@test:/tmp/so/trunk$ ls /tmp > x/test.txt 
test@test:/tmp/so/trunk$ svn add x/ 
A         x
A         x/test.txt
test@test:/tmp/so/trunk$ svn ci -m "test"
Adding         trunk/x
Adding         trunk/x/test.txt
Transmitting file data .
Committed revision 2.
test@test:/tmp/so/trunk$ cd /tmp/ 
test@test:/tmp$ svn co http://localhost:8080/svn/stackoverflow so1 --username=admin 
A    so1/trunk
A    so1/trunk/x
A    so1/trunk/x/test.txt
A    so1/branches
A    so1/tags
Checked out revision 2.
test@test:/tmp$ cd /tmp/so1/trunk/ 
test@test:/tmp/so1/trunk$ svn remove x 
D         x/test.txt
D         x
test@test:/tmp/so1/trunk$ svn ci -m "" 
Deleting       trunk/x

Committed revision 3.
test@test:/tmp/so1/trunk$ mkdir x 
test@test:/tmp/so1/trunk$ cp ../../so/trunk/x/test.txt x 
test@test:/tmp/so1/trunk$ ll /tmp > x/test.txt 
test@test:/tmp/so1/trunk$ svn add x/ 
A         x
A         x/test.txt
test@test:/tmp/so1/trunk$ svn ci -m ""
Adding         trunk/x
Adding         trunk/x/test.txt
Transmitting file data .
Committed revision 4.
test@test:/tmp$ cd so/trunk/
test@test:/tmp/so/trunk$ svn up
D    x
A    x
A    x/test.txt
Updated to revision 4.
test@test:/tmp/so/trunk$ 

Apparently I tried the same approach which you did and did not face any problem again. What version of svn are you using ?

export REPOPATH=/tmp/svntest
test@test:/tmp/co2/trunk$ rm -rf $REPOPATH
test@test:/tmp/co2/trunk$ mkdir $REPOPATH
test@test:/tmp/co2/trunk$ svnadmin create $REPOPATH/repo
test@test:/tmp/co2/trunk$ svn co file:///$REPOPATH/repo co1
svn: Repository UUID '2d803eb8-2030-4dd3-bb6f-34ab07c74813' doesn't match expected UUID '82764ae8-6410-4565-933f-9a420cb60013'
test@test:/tmp/co2/trunk$ svn co file:///$REPOPATH/repo co2
svn: Repository UUID '2d803eb8-2030-4dd3-bb6f-34ab07c74813' doesn't match expected UUID '82764ae8-6410-4565-933f-9a420cb60013'
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co1
bash: cd: /tmp/svntest/co1: No such file or directory
test@test:/tmp/co2/trunk$ mkdir folder
mkdir: cannot create directory `folder': File exists
test@test:/tmp/co2/trunk$ echo content > folder/file.txt
test@test:/tmp/co2/trunk$ svn add folder
svn: warning: 'folder' is already under version control
test@test:/tmp/co2/trunk$ svn commit folder -m ""
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co2
bash: cd: /tmp/svntest/co2: No such file or directory
test@test:/tmp/co2/trunk$ svn up
At revision 10.
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co1
bash: cd: /tmp/svntest/co1: No such file or directory
test@test:/tmp/co2/trunk$ svn del folder
svn: Use --force to override this restriction
svn: 'folder/file.txt' is not under version control
test@test:/tmp/co2/trunk$ svn commit -m ""
test@test:/tmp/co2/trunk$ mkdir folder
mkdir: cannot create directory `folder': File exists
test@test:/tmp/co2/trunk$ svn add folder
svn: warning: 'folder' is already under version control
test@test:/tmp/co2/trunk$ svn commit -m ""
test@test:/tmp/co2/trunk$ 
test@test:/tmp/co2/trunk$ cd $REPOPATH/co2
bash: cd: /tmp/svntest/co2: No such file or directory
test@test:/tmp/co2/trunk$ echo changed_content > folder\file.txt
test@test:/tmp/co2/trunk$ svn up
At revision 10.
test@test:/tmp/co2/trunk$ svn --version
svn, version 1.6.6 (r40053)
   compiled Dec 12 2009, 05:04:54

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme
蓝海似她心 2024-10-05 20:30:47

在这种特殊情况下,我认为您必须手动重新应用本地更改。也就是说,创建一个补丁文件(svn diff > mine.patch,或将文件复制到其他地方),恢复您的更改或使用他们的更改进行解析,然后应用补丁(或将文件复制回来)。也许您需要在应用更改之前将文件的基础复制回重新创建的文件夹中。

就像泽勒斯所说,这是颠覆的黑暗面,这是当前实现无法处理的。话又说回来,删除一个文件夹并添加一个同名的文件夹听起来不太正确。您期望颠覆会做什么?如果该文件未在文件夹中重新创建怎么办?如果内容不同怎么办?

尝试通过不删除您想要保留的文件夹来完全避免这种情况:)

In this particular case, I think you'll have to re-apply the local changes manually. That is, create a patch file (svn diff > mine.patch, or copy files somewhere else), revert your changes or resolve using theirs, then apply the patch (or copy files back). Perhaps you will need to svn copy the base of your files back in the recreated folder before applying your changes.

Like zellus said, it's the dark side of subversion, and this is something the current implementation is unable to handle. Then again, deleting a folder and adding an identically named one back in doesn't sound quite right. What would you expect subversion to do? What if the file is not recreated in the folder? What if its content is different?

Try avoiding the situation altogether by not deleting a folder you want to keep :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文