将文件添加到 SVN,然后在提交之前删除

发布于 2024-11-28 00:44:41 字数 175 浏览 3 评论 0原文

我想我是不小心了。

我使用 svn add 添加了一堆文件到 svn, 然后我看到添加了一些我不想要的文件,所以我用 rm 删除了它们。

现在我无法再提交,因为提交缺少文件。我尝试了 svn cleanup 但没有帮助。

我现在的工作选择是手动删除每个 .svn 目录,但这似乎是错误的。

I guess I was careless.

I added a bunch of files to svn with svn add,
then I saw a few files added that I didn't want so I deleted them with rm.

Now I can't commit anymore because the commit is missing files. I tried svn cleanup but it didn't help.

My working option now is to manually delete every .svn directory but that seems wrong.

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

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

发布评论

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

评论(6

月竹挽风 2024-12-05 00:44:41

据我了解,你遇到这种情况:

$ touch foo
$ svn add foo
A         foo
$ rm foo
$ svn ci
svn: Commit failed (details follow):
svn: 'foo' is scheduled for addition, but is missing

所以要修复它,请执行以下操作:(感谢 Linus!)

$ svn revert foo
Reverted 'foo'

或者您可以执行以下操作:

$ touch foo
$ svn delete --force foo

对于每个文件,您应该能够毫无问题地签入。

As I understand it you have this situation:

$ touch foo
$ svn add foo
A         foo
$ rm foo
$ svn ci
svn: Commit failed (details follow):
svn: 'foo' is scheduled for addition, but is missing

So to fix it do this: (thanks Linus!)

$ svn revert foo
Reverted 'foo'

or you can do this:

$ touch foo
$ svn delete --force foo

for each file, and you should be able to check in without problems.

无风消散 2024-12-05 00:44:41

如果您添加了一个包含子文件夹和文件的文件夹
然后您在提交之前删除了该文件夹。
在这种情况下,您可以执行以下操作。

$ svn revert <Deleted Folder Name> --depth infinity

If you added a folder with sub-folders and files inside
then you deleted the folder before you commit it.
In this case you can do as the following.

$ svn revert <Deleted Folder Name> --depth infinity
把回忆走一遍 2024-12-05 00:44:41

这实际上是@Gonzalo Mateo 的稍微修改版本,它解决了我的问题。

svn st  | grep '!' | sed 's/!M      \(.*\)$/"\1"/' | xargs svn revert --depth infinity

This is actually a slightly modified version of @Gonzalo Mateo, which solved my problem.

svn st  | grep '!' | sed 's/!M      \(.*\)$/"\1"/' | xargs svn revert --depth infinity
扛刀软妹 2024-12-05 00:44:41

如果您有多个目录并删除了多个文件,以下命令可能会有所帮助:

svn st  | grep '!M' | sed 's/!M      \(.*\)$/"\1"/' | xargs svn revert

我建议首先列出要恢复的文件。我们可以通过删除最后一个管道来做到这一点: svn st | grep '!M' | sed 's/!M \(.*\)$/"\1"/'.

分步命令说明:

  • svn st - 它列出了带有 !M 符号的添加和不正确删除文件
  • grep '!M'< /code> 它找到带有 !M 的行
  • sed 's/!M \(.*\)$/"\1"/' 这是用来摆脱带有空格的 !M 。它还会引用文件名,因此您不必担心文件中是否包含空格。
  • xargs svn revert 这将恢复列出的所有文件。

If you have multiple directories with multiple files deleted, the following command could help:

svn st  | grep '!M' | sed 's/!M      \(.*\)$/"\1"/' | xargs svn revert

I recommend first to list the files that are going to be reverted. We can do it by removing the last pipe: svn st | grep '!M' | sed 's/!M \(.*\)$/"\1"/'.

Step by step command explanation:

  • svn st - It lists added and unproperly deleted files with !M symbol
  • grep '!M' It finds the lines with !M
  • sed 's/!M \(.*\)$/"\1"/' This is used to get rid of the !M with the spaces. It will also quote the file names so you don't have to worry if files include spaces on them.
  • xargs svn revert This will revert all files listed.
韬韬不绝 2024-12-05 00:44:41

如果您 svn add X 一个文件,但尚未提交,那么稍后您决定要删除该文件(而不是提交它);您应该简单地使用 svn revert X 恢复您的 svn add X 命令。

然后它将“撤消”尚未提交的添加。

If you svn add X a file, but you haven't committed, then later you decide you want to delete that file (and not commit it); you should simply revert you svn add X command with svn revert X.

It will then "undo" the not yet committed add.

喜爱皱眉﹌ 2024-12-05 00:44:41

这解决了我的问题

svn st | grep '!' | sed 's/!M \(.*\)$/"\1"/' | xargs svn revert --depth infinity

您应该注意的一件事是,上面的代码仅适用于最新添加的内容。因此,如果出现错误,请执行另一个 svn ci ,然后再次运行上述代码。然后再次svn ci,直到恢复所有问题。

奖金:
添加别名(这是 Oh-My-ZSH Zsh Shell 的别名)

# SVN 恢复所有内容,例如硬重置
别名 sra="svn st | grep '!' | sed 's/!M \(.*\)$/"\1"/' | xargs svn revert --depth infinity"

现在 sraSVN 全部恢复 将使您的生活变得轻松。

This solved my problem

svn st | grep '!' | sed 's/!M \(.*\)$/"\1"/' | xargs svn revert --depth infinity

One thing you should note is that the above code only works for the latest additions. So, do another svn ci if it gives an error then run the above code again. Then again svn ci until you have reverted every problem.

Bonus:
Add an alias (this is for Oh-My-ZSH Zsh Shell)

# SVN revert everything like reset hard
alias sra="svn st | grep '!' | sed 's/!M \(.*\)$/"\1"/' | xargs svn revert --depth infinity"

Now sra i.e. SVN Revert All will make your life easy.

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