将文件添加到 SVN,然后在提交之前删除
我想我是不小心了。
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
据我了解,你遇到这种情况:
所以要修复它,请执行以下操作:(感谢 Linus!)
或者您可以执行以下操作:
对于每个文件,您应该能够毫无问题地签入。
As I understand it you have this situation:
So to fix it do this: (thanks Linus!)
or you can do this:
for each file, and you should be able to check in without problems.
如果您添加了一个包含子文件夹和文件的文件夹
然后您在提交之前删除了该文件夹。
在这种情况下,您可以执行以下操作。
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.
这实际上是@Gonzalo Mateo 的稍微修改版本,它解决了我的问题。
This is actually a slightly modified version of @Gonzalo Mateo, which solved my problem.
如果您有多个目录并删除了多个文件,以下命令可能会有所帮助:
我建议首先列出要恢复的文件。我们可以通过删除最后一个管道来做到这一点: 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:
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
symbolgrep '!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.如果您
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 yousvn add X
command withsvn revert X
.It will then "undo" the not yet committed add.
这解决了我的问题
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"
现在
sra
即 SVN 全部恢复 将使您的生活变得轻松。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 againsvn 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.