TFS 2008 源代码管理 - 销毁所有已删除项目的快速方法
我有一堆源代码管理文件夹,我想删除它们中不再需要的所有项目。这些项目已被删除(代码已被移动或重写),并且由于我们大多数人默认使用“显示已删除项目”选项,因此其中一些文件夹现在显示更多已删除项目和文件夹以及合法项目。我想确保所有这些冗余代码都永远消失——因为它绝对不会被需要。这些是从旧项目的分支构建的新项目,但到目前为止还没有人在使用。
不过,有相当多的文件分布在多个文件夹中,因此我宁愿避免单独处理每个文件。我也是在命令行,而不是使用 API。
我知道最终我将需要 tf destroy 命令。
我还知道 tf dir [wildcard] /recursive /deleted
将返回路径中的所有已删除项目(不幸的是与所有合法项目一起)。
谁能想出一个快速做到这一点的好方法?
我想到了两种解决方案:
1)获取 dir 命令的输出并找到后面带有 :Xnnnnnnn
的所有项目 - 这些是已删除的项目;然后简单地吐出一堆 tf destroy 调用,或者构建一个响应文件(尽管不确定这一点)。这听起来像是 Powershell 的潜在用途,但实际上还没有做任何事情...
2) 准备好所有项目,然后简单地从 TFS 中销毁它们,然后重新添加它们,以便只有所需的内容然后在TFS中。但是,这确实删除了可能有用的分支关系,因为一段时间内我将不得不维护其中一些库的两个版本(升级前和升级后)。不理想,但我对此无能为力。
显然,选项 2 是一个作弊,但它会起作用 - 我只是理想地喜欢一个可重用的脚本,可以在未来用于 TFS 中的任何文件夹(其他几个团队有其他长期项目,可以使用全面净化!)。
提前致谢。
I have a bunch of source control folders for which I want to get rid of all items that are no longer required. These items have been deleted (code has been moved or rewritten) and, because most of us use the 'Show Deleted Items' option by default some of these folders now show more deleted items and folders and legitimate items. I want to make sure all this redundant code is gone, forever - as it most definitely will not ever be required. These are new projects being built from branches of older ones that, as yet, nobody is using.
There's quite a lot of files spread across multiple folders, though, so I'd rather avoid having to do each one individually. I'm at the command-line too, not using the API.
I know ultimately I will need the tf destroy
command.
I also know that tf dir [wildcard] /recursive /deleted
will return all deleted items within a path (unfortunately alongside all legitimate items).
Can anyone think of a good way of doing this quickly?
I've thought of two solutions:
1) Take the output of the dir command and find all the items that have :Xnnnnnnn
after - these are the deleted items; then simply spit out a bunch of tf destroy calls, or construct a response file (not sure about this bit though). This sounds like a potential use for Powershell, but haven't actually done anything with that yet...
2) Get all the projects ready, and then simply destroy them from TFS and then re-add them so that only the required stuff is then in TFS. However, this does remove the branch relationship which could be useful because for a while I'm going to have to maintain two versions of some of these libraries (pre and post upgrade). Not ideal, but nothing I can do about it.
Obviously Option 2 is a cheat but it'll work - I'd just ideally like a reusable script that could be used for any folder in TFS in the future (a couple of other teams have other long-lived projects that could do with a full purge!).
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我写了一个控制台应用程序(.Net 4):
不用说我对此不提供任何保证 - 它会毁掉 TFS 中的项目!!!
更新(2012 年 5 月 8 日)如果您在包含大量(我的意思是数千或数万)已删除项目的文件夹上运行此更新,则在 TFS 命令行超时之前,它可能无法完成。此命令花费的大部分时间是生成 .tfc 脚本。如果您运行它并发现这种情况发生,请尝试首先定位某些子文件夹
您必须传递要删除的 TFS 文件夹,例如“$/folder”。如果您只是通过它,那么所有匹配的已删除项目都将被一一检测并销毁。
由于某种原因 - 如果您不小心传递了一个实际上并不存在的文件夹,那么该操作将永远。当然,CTRL+C 会阻止它。
应用程序使用
/deleted
开关在文件夹上执行递归目录。然后它会遍历输出中的每一行,查找删除提示,即带有
;Xnnnnnnn
的项目。如果找到,它将将该项目的完整 tfs 路径添加到列表中。完成后,列表按长度降序排序,并将内容写入 tf.exe 命令行的 tfc 响应文件。
如果指定了
preview
选项,则使用 /preview 开关写出tf
命令(请参阅 TFS 销毁)那么删除实际上并没有执行。
最后,您可以指定
norun
,这会导致创建 tfc 文件,但不会实际运行。Okay so I wrote a console app (.Net 4):
IT GOES WITHOUT SAYING I OFFER NO WARRANTY ABOUT THIS - IT WILL DESTROY ITEMS IN TFS!!!!
Update (8th May 2012) If you run this on a folder that has masses and masses (I mean thousands or tens-of-thousands) of deleted items it might not complete before the TFS command-line times out. The majority of the time taken by this command is in generating the .tfc script. If you run it and find this happening, try to targetting some child folders first
You must pass the TFS folder to be deleted e.g '$/folder'. If you just pass that, then all matching deleted items will be detected and destroyed, one by one.
For some reason - if you accidentally pass a folder that doesn't actually exist then the operation takes forever. A CTRL+C will stop it, of course.
The app does a recursive dir on the folder, with the
/deleted
switch.It then runs through each line in the output, looking for the delete hint, i.e. items with
;Xnnnnnnn
. If found, it adds the full tfs path for that item to a list.After complete, the list is sorted by length in descending order and the contents written out to a tfc response file for the
tf.exe
command line.If the
preview
option is specified then thetf
commands are written out with the /preview switch (see TFS Destroy on MSDN)Then the deletions aren't actually performed.
Finally, you can specify
norun
which causes the tfc file to be created, but not actually run.我知道这是一个老问题,但我认为它会有所帮助。
我们在 VSO 下有一个包含 20 多个团队项目的旧集合,确实需要清理我们的团队项目。这段代码对我们来说非常有效。
我使用了 Microsoft.TeamFoundationServer.ExtendedClient NuGet 包。
I know it is an old question but I think it can be helpful.
We have an old collection with 20+ team projects under VSO and really needed to clean up our team projects. This code worked perfectly for us.
I used Microsoft.TeamFoundationServer.ExtendedClient NuGet package.