用户删除文件并创建同名新文件时 TFS 回滚

发布于 2024-08-08 22:20:10 字数 254 浏览 6 评论 0原文

有人(除了我自己)意外删除了 TFS 中的文件并将其签入。然后他发现了自己的错误并想要替换丢失的文件,他做到了 - 从他自己的硬盘驱动器。 在他的错误和我发现它之间,其他人对相邻文件进行了更改。 现在,我想将已删除的文件回滚到删除之前的状态,但是当我尝试时,我在原始文件和替换文件之间(如果我理解正确的话)出现文件名冲突错误。

我无法回滚整个项目,因为已经完成了其他工作,我只想将这些文件恢复到“之前”的状态。

有人遇到过这个问题并解决了吗?或者说没有解决办法。

Someone (other than myself) accidentally deleted files in TFS and checked it in. He then discovered his error and wanted to replace the lost files, which he did - from his own hard drive.
In between his error and my discovery of it, others have made changes to adjacent files.
Now, I want to roll the deleted files back to their state before the delete, but when I try I get a filename collision error between (if I understand it correctly) the original files and his replacements.

I can't roll the entire project back since there has been other work done, I just want to get these files back to how they were "before".

Has anyone had this problem and solved it? Or is there no solution.

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

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

发布评论

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

评论(3

悟红尘 2024-08-15 22:20:10

感谢大家的意见。
为了供将来参考,这就是我最终解决此问题的方法:

首先,我获取了该文件的本地副本。

然后,在源代码管理资源管理器中,我将包含该文件的文件夹回滚到旧文件已被删除但新文件尚不存在的变更集。
我取消删除了该文件并签入,从而“从远处”带回了原始文件。

之后,几乎就是将我的本地副本和恢复的文件放入 diff 工具(我使用 BeyondCompare BTW)并更正恢复的文件以匹配新版本。

我可以这样做有几个原因,即:

  • 文件的删除和重新添加是在两个连续的变更集中完成的。
  • 恢复的文件和本地副本之间的差异“非常小”(即,添加了一个方法,并在另一个方法中进行了一些更改)。

我不知道如果我们没有错过有问题的文件,直到几周后,我们会对周围的代码进行一些更改,那么会发生什么。我也不知道对本地版本所做的任何实质性更改对可恢复性意味着什么。

Thank you all for your input.
For future reference, this is how I finally solved the case:

Firstly, I took a local copy of the file.

In Source Control Explorer, I then rolled back the folder containing the file to the changeset where the old file had been deleted but the new file was not yet present.
I undeleted the file and checked in, thus bringing the original back "from beyond".

After that, it was pretty much a case of putting my local copy and the recovered file into a diff tool (I used BeyondCompare BTW) and correct the recovered file to match the new version.

I could do this due to a couple of reasons, namely:

  • The deletion and the re-adding of the file was done in two consecutive changesets.
  • The difference between the recovered file and the local copy was "pretty minor" (i.e., an added method and a couple of change hacks in another).

I have no idea what would have happened if we for instance hadn't missed the file in question until a couple of weeks later, where we would have had several changes made to the surrounding code. I also have no clue as to what any substantial changes made to the local version had meant in terms of recoverability.

岁月流歌 2024-08-15 22:20:10
  • 将您的解决方案回滚到另一个工作副本。
  • 从该工作副本中提取已删除的文件,并将它们放回当前工作副本中。
  • 将这些文件检入当前项目中。

我在这里看到的唯一问题是您可能会丢失已删除文件的历史记录。

  • Roll back your solution to another working copy.
  • Pull the deleted files from that working copy and them back into your current working copy
  • The checkin those files into the current project.

Only problem I can see here, is you may lose history on the deleted file.

拿命拼未来 2024-08-15 22:20:10

听起来像是Power Tools的工作。给你:

$deletedFiles = 
    Get-TfsChangeset 12345| 
    % { $_.changes } | 
    ? { $_.changetype.tostring().contains("Delete") } |
    % { $_.item.serveritem }

$deletedFiles | 
    Add-TfsPendingChange -Delete | 
    New-TfsChangeset -Comment "Delete mistakenly re-added files"

$deletedFiles |    
    Get-TfsChildItem -Deleted |
    ? { $_.changesetid -eq 12345 } |
    # this bit of ugliness is required by a bug in the Power Tools
    % { "$($_.serveritem);X$($_.deletionid)" } | 
    Add-TfsPendingChange -Undelete |
    New-TfsChangeset -Comment "Undelete old files"

正如评论中提到的,在理想的 Powershell 世界中,最终管道中丑陋的字符串解析应该是不必要的。如果事情按预期进行,您可以删除该行(或者等效地,将其替换为 Select-TfsItem | )。不幸的是,电动工具似乎无法按照我的预期处理删除 ID。

无论如何,这个脚本应该满足您的要求。注意:

  • 如果需要,将 12368 替换为用户意外删除文件的变更集
  • ,将第二个管道中的删除+签入替换为 Destroy,
  • 这不会恢复系统中的任何其他更改(包括 #12345 中的其他更改),只是恢复导致文件名冲突的

Sounds like a job for the Power Tools. Here you go:

$deletedFiles = 
    Get-TfsChangeset 12345| 
    % { $_.changes } | 
    ? { $_.changetype.tostring().contains("Delete") } |
    % { $_.item.serveritem }

$deletedFiles | 
    Add-TfsPendingChange -Delete | 
    New-TfsChangeset -Comment "Delete mistakenly re-added files"

$deletedFiles |    
    Get-TfsChildItem -Deleted |
    ? { $_.changesetid -eq 12345 } |
    # this bit of ugliness is required by a bug in the Power Tools
    % { "$($_.serveritem);X$($_.deletionid)" } | 
    Add-TfsPendingChange -Undelete |
    New-TfsChangeset -Comment "Undelete old files"

As alluded to in the comment, the ugly string parsing in the final pipeline shouldn't be necessary in an ideal Powershell world. If things worked as intended, you could remove that line (or equivalently, replace it with Select-TfsItem | ). Unfortunately, the Power Tools don't appear to handle deletion IDs as well as I intended them to.

Anyway, this script should do what you asked. Notes:

  • replace 12368 with the changeset where the user accidentally deleted the files
  • if desired, replace the delete + checkin in the 2nd pipeline with Destroy
  • this doesn't revert any other changes in the system (including other changes in #12345), just the ones causing the filename collision
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文