简体   繁体   中英

Add files to SVN then delete before commit

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.

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.

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

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

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

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"/' svn st | grep '!M' | sed 's/!M \\(.*\\)$/"\\1"/' 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.

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.

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 ie SVN Revert All will make your life easy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM