SharpSvn:恢复已删除文件的正确方法

发布于 2024-09-25 06:44:11 字数 608 浏览 8 评论 0原文

请考虑以下场景:
1. 用户 A 创建并提交一个文件(假设 file1.txt)。
2. 用户 B 从存储库中删除该文件。
3. 用户 A 在其本地工作副本中拥有该文件并希望恢复它。用户发现完成Update()之后。

实现这一目标的正确方法是什么?

到目前为止我已经尝试过:
- Client.Revert() 后跟 Update 但我没有看到任何变化。
- Client.Merge(local_working_copy, SvnUriTarget_of_repository, revision_range_ Between_the_previous_and_new) - 仍然没有变化。
- Client.DiffMerge(),其中目标路径是文件的本地路径,merge_from 是具有先前版本号的存储库中的路径,merge_to 是具有新版本号的本地路径修订。 - 我收到一个异常,说该文件不受版本控制。无法添加它,因为它在本地不再存在。当我将目标路径替换为存储库路径时,我收到一个异常,说这不是工作副本。

请帮忙,
诺亚

Please consider the following scenario:
1. User A creates and commits a file (lets say file1.txt).
2. User B deletes this file from the repository.
3. User A has the file in his local working copy and would like to restore it. The user finds that out after an Update() was done.

What is the proper way to achieve this?

So far I've tried:
- Client.Revert() followed by Update but I see no change.
- Client.Merge(local_working_copy, SvnUriTarget_of_repository, revision_range_between_the_previous_and_new) - still no change.
- Client.DiffMerge(), where the target path is the local path of the file, the merge_from is the path in the repository with the previous revision number, and the merge_to is the local path with the new revision. - I get an exception saying that the file is not under version control. It can't be added since it doesn't exist locally anymore. When I replaced the target path to be the repository path I get an exception saying this is not a working copy.

Please help,
Noa

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

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

发布评论

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

评论(2

智商已欠费 2024-10-02 06:44:11

您应该反转修订属性,因为您正在反转合并。这意味着您必须创建一个 SvnRevisionRange ,如下所示:

new SvnRevisionRange(newRevision, oldRevision);

当您从旧到新使用时,您将尝试再次应用相同的更改(这是一个空操作,因为它已经发生了)。

You should reverse the revision properties, because you're reversing the merge. This means you have to create an SvnRevisionRange like:

new SvnRevisionRange(newRevision, oldRevision);

When you use from old to new, you're trying to apply the same change again (which is a no-op because it has already happened).

怀念你的温柔 2024-10-02 06:44:11

对于可能需要此操作并且以前没有 SVN 经验的其他人:

运行更新时,请使用 这个有用的答案订阅 Update() 事件。这样您就可以保存已删除文件的所有名称(或您感兴趣的任何其他操作)。

然后,在 Update() 完成后,您可以使用 Copy(),如下所示:
Copy(new SvnUriTarget(path/to/file/in/repository, new SvnRevision(the_old_revision_which_had_the_files)), local/path/to/file);

现在剩下的就是 Commit() 将文件放回存储库,您就完成了:)

Noa

For anyone else who might need this and has no previous experience with SVN:

When running update, use this useful answer to subscribe to the Update() event. This way you can save all the names of the files that were deleted (or whatever other action interests you).

Then, after Update() is done, you can use Copy() as follows:
Copy(new SvnUriTarget(path/to/file/in/repository, new SvnRevision(the_old_revision_which_had_the_files)), local/path/to/file);

Now all that's left is to Commit() the file(s) back to the repository and you're done :)

Noa

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