TFS:如何撤消批处理文件中未修改文件的签出
我们使用批处理文件来生成代码,它会自动从 Team Foundation Server (TFS) 中检出生成的文件,以便重新生成它们。 这些文件中的大多数都没有被修改,但生成器事先并不知道这一点。
“tfs undo”命令撤消签出,但会提示是否修改了某些内容(我们不想这样做)。 我们也不想立即签入生成的文件。
是否有一个命令(或一系列命令)可以在不提示用户的情况下撤消所有未修改文件的签出?
We use a batch file to generate code, and it automatically checks out the generated files from Team Foundation Server (TFS) so that it can regenerate them. The majority of these files are not modified, but the generator does not know this ahead of time.
The "tfs undo" command undoes the checkout, but prompts if some have been modified (which we don't want to do). We also do not want to check in the generated files right away.
Is there a command (or series of commands) to undo checkout of all unmodified files without prompting the user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
查看 2011 年 8 月的 Team Foundation Server Power Tools< 的 Undo Unchanged 命令< /a>
感谢 Matt Florence 更新链接。
感谢 Ray Vega 提供实际语法 .
Take a look on Undo Unchanged command of the Team Foundation Server Power Tools August 2011
Thanks Matt Florence for link update.
Thanks Ray Vega for actual syntax.
安装 Team Foundation Server Power Tools 并使用以下命令从命令行运行以下命令tfpt.exe 位于项目工作区目录的根目录:
c:\myProject> tfpt uu 。 /noget /recursive
强烈建议包括
/noget
,因为它可以防止强制“获取最新”所有项目文件,这取决于总数可能需要很长时间。Install Team Foundation Server Power Tools and run the following from the command line using tfpt.exe at the root of your project's workspace directory:
c:\myProject> tfpt uu . /noget /recursive
Including
/noget
is highly recommended since it prevents a forced 'get latest' of all your project's files which depending on the total number can take a extremely long time.谢谢@mike & @ray,
我希望让它变得更容易。
在 VS 中,在“工具”菜单中,单击“外部工具”。
单击添加。
输入标题。
命令:tfpt.exe
参数:uu 。 /noget /recursive
初始目录:[可以通过箭头按钮选择]。
“工具”菜单中添加了两个新命令。
需要时使用它们。
享受吧,
奥菲尔
Thank you @mike & @ray,
I wish to make it easier.
In VS, at Tools menu, click on "External Tools".
Click Add.
Enter title.
Command: tfpt.exe
Arguments: uu . /noget /recursive
Initial Directory: [you can choose from the arrow button].
Two new command are added to Tools menu.
Use them when needed.
Enjoy,
Ofir
Visual studio 就会知道签出的文件是否已更改或没有更改。
警告:此方法还会删除新文件,即尚未签入到 TFS 的文件。 如果您想保留这些文件,只需将它们从您“撤消”的文件集中排除即可。
Visual studio will know if the checked out file has changes or none.
WARNING: This method also removes new files, i.e. files that are not yet checked in to TFS. If you want to keep these files then simply exclude them from the set of files you "undo".
仅使用 TFS2017 和 VS2017/VS2019 时的答案更新了此问题。
TFS 2017 不存在强大的工具,旧的工具不能与它很好地协同工作,但显然大部分功能已转移到 VS2017 本身或插件(见下文)。
Visual Studio 2017/2019 扩展
某些操作(例如撤消未更改的文件)已移至
VS2017 的 扩展
VS2019 扩展
“撤消未更改”按钮位置:
< img src="https://i.sstatic.net/wqYDr.png" width="300" alt="撤消未更改的按钮位置">
已知错误
您必须打开“源代码管理资源管理器”(并将其保持打开状态)以便“撤消未更改”显示在“待处理更改”视图的“操作”菜单中。
在此处报告。
Windows Shell 集成扩展
此外,您仍然可以通过单独的设置 Windows Shell 集成安装程序 不再链接到 TFS Power Tools。
Windows shell 集成的工作方式与之前的 powertools 并不完全相同,但最重要的操作对我来说很有效。
Updated this question with an answer when working with TFS2017 and VS2017/VS2019 only.
The power tools does not exist for TFS 2017 and the old ones can't work well together with it, but apparently most of the functionality has been moved to VS2017 itself or plugins (see below).
Visual Studio 2017/2019 Extension
Some actions like undo unchanged files have moved to an
extension for VS2017
extension for VS2019
"Undo Unchanged" button location:
Known bug
You have to open the 'Source Control Explorer' (and leave it open) so that the 'Undo Unchanged' is displayed in the Action menu of the Pending Changes view.
reported here.
Windows Shell Integration Extension
Also, you can still set up Windows shell integration through an separate installer which is no longer linked to TFS Power Tools.
The windows shell integration do not work exactly the same as the powertools before, but the most important actions worked for me.
如果您只需再次签入所有已签出的文件,TFS 就会足够智能地找出哪些文件发生了更改,并仅将它们包含在服务器上记录的变更集中。
TFS 通过比较签入前后文件内容的 MD5 哈希来实现此目的。
这一切都假设您的生成过程纯粹是更新同一组文件,即您永远不会遇到下一代不需要上一代生成的文件的情况(即您希望挂起删除)对于该文件)或文件更改名称。
如果您的进程可能需要删除文件,那么最好的选择可能是查看 Team Foundation Power Tools 命令 (tfpt) 并使用tfpt online 命令只会检查已更改的文件,并且足够智能,可以挂起删除不再需要的任何文件或更改名称和挂起添加。
祝你好运,
马丁。
If you simply check all the files back in again that you checked out, TFS is smart enough to figure out which ones changes and only include them in the changeset that is recorded on the server.
TFS does this by comparing MD5 hashes of the files contents before and after check-in.
This is all assuming that your generation process is purely updating the same set of files, i.e. you will never have the case where a file that was generated in a previous generation is not needed in the next generation (i.e. you would want to pend a delete for that file) or that the files change name.
If your process could potentially need files deleting, the your best bet might be to look at the Team Foundation Power Tools command (tfpt) and use the tfpt online command that will only check out the files that have changed, and will be smart enough to pend deletes for any files that are no longer needed or changed name and pend adds.
Good luck,
Martin.
请注意,TFS 撤消不会恢复文件系统的“修改日期”值。 这是非常令人沮丧的,尤其是当您使用 robocopy 等工具来同步远程计算机时。 即使在撤消签出之后,如果您保存了文件从而更新了“修改日期”值,则即使在撤消签出之后,更新后的值也会保留下来。
Beware that TFS undo will not revert back the File System's "Date Modified" value. This is very frustrating especially if you use tools like robocopy to sync up remote machines. Even after you undo your check out, if you saved the file thereby updaing the "Date Modified" value, that updated value will stick around even after an undo checkout.
关于 tfpt 的 uu 选项(在大多数其他答案中推荐),有几点一开始我并不清楚。 首先,这是命令行帮助,可以使用命令
tfpt uu /?
访问现在让我分解一下其他答案中推荐的命令。
tfpt uu
指定我们希望使用“Undo Unchanged”命令。.
指示(我猜)当前工作目录应用作文件规范。/noget
确保在撤消未更改的文件之前不会调用“获取最新版本”。/recursive
确保不仅考虑文件规范,而且考虑所有递归子文件夹和文件。 这似乎取决于文件规范 - 如果没有提供,则处理整个工作区。因此,关于上面的命令,这里有一些需要注意的事情......
我发现以下命令最适合我 - 它将处理整个工作区。
tfpt uu /noget
请注意,它仍然依赖于工作目录,因为 tfpt 使用它来确定应处理哪个工作空间。 但只要您提供工作区中文件或文件夹的路径,就可以开始了。
There are a couple of points regarding the uu option for tfpt (recommended in most of the other answers) that were not clear to me at first. Firstly, this is the command line help that can be accessed with the command
tfpt uu /?
Now let me break down the command that is recommended in the other answers.
tfpt uu
specifies that we wish to use the 'Undo Unchanged' command..
indicates (I guess) that the current working directory should be used as the filespec./noget
ensures that 'get latest version' is not called before undoing the unchanged files./recursive
ensures that not just the filespec will be considered but all recursive child folders and files. This seems to be dependent on the filespec - if there is none provided then the whole workspace is processed.So there are a couple of things to note here regarding the command from above...
I have found that the following command works best for me - it will process the entire workspace.
tfpt uu /noget
Note that it is still dependent on the working directory in that tfpt uses it to determine which workspace should be processed. But as long as you provide a path to a file or folder within the workspace, you are good to go.
我可以在上面看到 Ray LionFang 的方法。 由于我没有代表,因此无法发表评论。 虽然我喜欢这种方法,因为不需要对工具等进行任何更改......
....该方法存在一个问题,即点击“全部否”会保留一些未修改的文件。 它似乎会执行诸如“撤消未修改的文件”之类的操作,直到它到达实际修改的第一个文件,然后忽略其余未修改的文件(如果这有意义)。 这种效果我只偶尔见过一次。
一个可能的解决方法是遵循上述过程,但不要对每个文件单击“否”,而是单击“否”。 由于这可能需要一段时间,具体取决于您正在处理的文件数量,因此我通常所做的是按住“ALT + N”,它只是加速浏览所有文件,同时撤消所有未修改的文件。
I can see Ray LionFang's approach above. Can't comment there since I don't have the rep. While I like this approach since there's no changes required to Tools etc........
.......there's a problem with that approach in that hitting "No To All" retains a few files which are not modified. It seems to do something like Undoing unmodified files until it hits the first file that's actually modified and then ignores the rest of the unmodified files, if that makes any sense. I've only seen this effect once in a while.
A potential work-around is to follow the above process but instead of hitting "No To All", hit "No" for each file. Since this can take a while depending on the number of files you're working with, what I normally do is to hold down "ALT + N", and it just speeds through all the files while undoing ALL unmodified files.
我来晚了一点,但是如果您可以控制批处理脚本,您可以在生成过程中不检查任何文件,然后运行以下内容:
以确保您仅签出您想要签入的文件。 您可以在此处阅读有关协调命令及其语法的更多信息:
https://learn.microsoft.com/en-us/azure/devops/repos/tfvc/reconcile-command
I'm a bit late to the party, but if you have control over the batch script you could simply not check out any files during the generation process and then run something along the lines of:
to make sure you check out only the files you intend to check-in. You can read more about the reconcile command and its syntax here:
https://learn.microsoft.com/en-us/azure/devops/repos/tfvc/reconcile-command
我发现既不会导致 Visual Studio 崩溃也不会花费很长时间的最安全、最快的方法是:
1- 打开开发人员命令提示符。 您可以从 Visual Studio 中执行此操作,在顶部的搜索字段中键入开发人员命令提示符。
2- 使用以下命令获取所有签出文件的状态:
3- 然后您将获得与以下内容类似的项目列表:
然后复制你想要批量撤消img中从1开始的所有内容的目录路径。 在下面的命令中将其填入双引号之间,而不是 PUT_1_HERE。 对 2 和 3 执行相同的操作(不带双引号)。
4- 执行命令,瞧,无论要撤消的文件数量有多大,都需要几秒钟的时间。
The safest and fastest way I found which neither causes Visual Studio to crash nor takes a long time is:
1- Open the developer command prompt. You can do that from Visual Studio, type developer command prompt in the search field at the top.
2- get the status of all checkouted files using the following command:
3- Then you'll get a list of similar items to the following:
Then copy the path of the directory you want to batch undo everything under from 1 in the img. Fill in that in the command below between the double quotations instead of PUT_1_HERE. Do the same for 2 and 3 without double quotations.
4- Execute the command and Voila it should take some seconds regardless how large the number of files to undo is.
据我了解,在 TFS 中,如果您签出团队项目,则会签出整个项目,并且您无法控制哪些文件被删除。 如果您想阻止签入某些文件,您可以锁定它们。
在工作中,我们都讨厌 TFS。
As far as I understood, in TFS if you checkout a team project, the whole project is checked out and you do not have control of which files are brought down. If you want to prevent checkins to certain files, you can lock them.
At work, we all hate TFS.