删除“已删除”来自本地存储库的文件

发布于 2025-01-01 07:37:22 字数 1018 浏览 0 评论 0原文

如何删除已从Repo删除但本地尚未删除的文件?

本质上,我正在 powershell 中编写一个构建脚本,它需要从存储库和签出中获取最新的更改,但可能存在从存储库中删除的文件,但这些文件还没有被删除。尚未从我的本地结帐中删除。我的意思是,一种解决方案是删除所有内容并进行干净的结帐,但这相当昂贵并且需要很长时间。我还可以执行 svn status 并查找带有“D”的任何内容并在本地删除它们,但这相当乏味。我还想覆盖所有冲突并强制签出需要合并的文件。

是否有一些简单的命令,例如我缺少的恢复或结帐开关?


**编辑:实际上我需要处理两种不同的情况:

A 部分) 在一个部分中,我需要单独保留工作副本中修改的任何内容,只需检查不冲突或合并的更改。我需要它永远不会中止,这意味着我只想扔掉任何有问题的东西并保留工作/本地副本。

我正在考虑使用:svn update --accept mine-full --force注意:这是在根目录而不是单个文件上)

B 部分) 在另一部分中,我想覆盖任何更改并删除在存储库中删除的文件。

我正在考虑使用:svn update --accept Theirs-full --force注意:这是在根目录而不是单个文件上)

这可行吗?或者 --force (或 --accept)不是我想要使用的?


我对使用更新的主要担心是,如果出现问题,它会中止整个过程,不是吗? --force 对 svn update 有何作用?它也不会删除未版本控制的项目。

恢复也不完全是我所需要的,是吗?它不会删除我的任何未版本控制的项目。

另外,如果已经有本地文件,签出是否只执行与更新相同的操作?在什么都不存在的情况下,只使用结账会简单得多。问题是我无法使用 svn checkout 指定 --accept 参数。我想我可以测试该文件夹是否存在,然后相应地进行签出或更新。

How do I delete files which have been deleted from the Repo but have not been deleted locally yet?

Essentially, I'm writing a build script in powershell that needs to get the most up-to-date changes from the repo and checkout, but there might be files which were deleted from the repo which haven't yet been deleted from my local checkout. I mean, one solution is to just delete everything and do a clean checkout, but that's rather expensive and would take a long time. I could also do a svn status and look for anything with a "D" and delete them locally, but that's rather tedious. I'd like to also just overwrite any conflicts and --force the checkout for files which need to be merged.

Is there some simple command like revert or a checkout switch that I'm missing?


**Edit: There are actually two different cases that I need to handle:

Part A) In one section, I need to leave anything modified in the working copy alone and just checkout the changes that aren't conflicts or merged. I need this to never abort, meaning that I just want to throw away anything that has a problem and keep the working/local copy.

I was thinking of using: svn update --accept mine-full --force (Note: This is on the root directory and not individual files)

Part B) In the other section, I want to overwrite any changes and delete files which were deleted in the repo.

I was thinking of using: svn update --accept theirs-full --force (Note: This is on the root directory and not individual files)

Would this work? Or is --force (or --accept) not what I want to be using?


My main concern with using update is that it will abort the entire process if there's a problem, won't it? What does --force do with svn update? It also doesn't delete unversioned items.

Revert isn't exactly what I need either, is it? It doesn't delete any of my unversioned items.

Also, doesn't checkout just do the same thing as update if there are already local files? It would be much simpler to just use checkout in the case where nothing exists yet. The problem is that I cannot specify the --accept parameter with svn checkout. I suppose I could test if the folder exists and then do a checkout or an update accordingly.

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

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

发布评论

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

评论(2

日暮斜阳 2025-01-08 07:37:22

对于 A 部分,我使用:

svn update --accept mine-full --force

对于 B 部分,我只是做了:

步骤 1:

svn revert $localPath

步骤 2:

svn update $localPath

步骤 3 (使用 powershell + svn status,但可以使用 rm -rf grep/sed in *nix 完成):

svn status $localPath --no-ignore |
                Select-String '^[?I]' |
                ForEach-Object {
                    [Regex]::Match($_.Line, '^[^\s]*\s+(.*)
).Groups[1].Value
                } |
                Remove-Item -Recurse -Force -ErrorAction SilentlyContinue

For Part A, I used:

svn update --accept mine-full --force

For Part B, I just did:

Step 1:

svn revert $localPath

Step 2:

svn update $localPath

Step 3 (using powershell + svn status, but can be done with rm -rf grep/sed in *nix):

svn status $localPath --no-ignore |
                Select-String '^[?I]' |
                ForEach-Object {
                    [Regex]::Match($_.Line, '^[^\s]*\s+(.*)
).Groups[1].Value
                } |
                Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
世界和平 2025-01-08 07:37:22

如果您手动删除该文件,它将被恢复,直到您将本地存储库更新到存储库中缺少该文件的相同版本为止。因此,第一个行动方案是尝试更新您的存储库。

svn update

有一些注意事项。首先,如果有人删除了该文件但没有签入他的删除,则该删除实际上并不在远程存储库中。其次,如果您修改了该文件,您可能会遇到冲突,因为存储库中删除的文件与磁盘上删除的文件不同。

假设存在某种冲突,这确实使更新变得困难。您应该尝试

svn revert <problem file name>

并再次尝试更新。

在没有清楚地了解正在发生的情况的情况下使用 --force 选项几乎总是一个坏主意。基本上就像不听专家建议一样。如果您比建议提供者拥有更多的专业知识,您就会知道需要避免的注意事项和痛点。如果你没有比建议者更多的专业知识,你就会伤害自己。 --force 不是“再试一次,忽略警告”标志,而是“无论如何都要做,即使它完全搞砸了”选项。

If you delete the file manually, it will be restored until you update your local repository to the same version that lacks the file in the repository. So, the first course of action is to attempt to update your repository.

svn update

There are a few caveats. First, if someone deleted the file but didn't checkin his deletion, the deletion isn't really in the remote repository. Second, if you modified the file, you might get a conflict, as the deleted file in the repository isn't the same deleted file on your disk.

Assuming that there are some sort of conflicts which does make the update difficult. You should try

svn revert <problem file name>

And attempt the update again.

Using the --force option without having an excellent picture of what is going on is almost always a bad idea. Basically it's like not listening to expert advise. If you have more expertise than the advice giver, you know the caveats and pain points to avoid. If you don't have more expertise than the advice giver, you are going to hurt yourself. --force is not a "try again, ignoring warnings" flag, it is a "do it anyway, even if it totally screws up things" option.

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