How do you revert ONLY directories in an SVN working copy?
Solution 1
You could use find
combined with svn revert
:
find . -type d | grep -v .svn | xargs svn revert
This won't touch any files inside the directories unless you use the -R
option (which is equivalent of --depth=infinity
).
Solution 2
Works on all platforms:
svn revert . --recursive
(Note that this will revert everything, not just directories.)
Solution 3
Firstly, make a copy of your working copy somewhere safe. :)
You can edit properties on svn working copies using commands like this:
REM Delete all mergeinfo properties recursively
svn propdel svn:mergeinfo -R
Solution 4
On Windows from the command line you could do this:
for /d /r %i in (*) do svn revert %i
If you call that from a batch file use %%i
instead. Please back up first!
This command is dirty and will go through all directories, even unmodified ones or the ones not under svn
. You could use something like this Ruby script to do in a cleaner way:
`svn st`.split("\n").grep(/^ M\s+(.*)/) { $1 }.find_all { |i| File.directory? i }.each do |i|
system "svn revert #{i}"
end
Related videos on Youtube
Rushyo
Liberal & opinionated hacker. Former Red Team Lead. Games dev. Law student (Completed 5/6 years). Sapere aude. Found an OWASP Top 10 in Stack Overflow. Also found critical 0-days in Dropbox (TLS Bypass), VMWare vSphere (Root) and .NET libraries (Cryptography). Used to work on Mozilla Firefox and Thunderbird. 20 years programming and counting.
Updated on May 18, 2022Comments
-
Rushyo about 2 years
I want to revert a directory and all sub-directories in an SVN working copy so they match the repository but I don't want to touch any files inside those directories.
One of my SVN applications recursively set an SVN property on every directory in my working copy but I want to revert those changes to stop it highlighting them and trying to commit the changes to the SVN properties. Simply changing it to match the HEAD doesn't work.
Any ideas? I've read through various SVN resources but none of them seem to deal with this edge case.
-
Rushyo almost 11 yearsWhy? The one I've accepted was entirely suitable. The one that has 40+ upvotes does not answer the question. Read it. Think about it. Read it again. Test it.
-
-
Petrucio almost 12 yearsWhy the heck did this answer only have 1 up-vote? The other answers make me want to stick a needle in my eye!
-
Rushyo almost 12 years@Petrucio Doesn't this also touch files? I don't want to recursively revert everything under the current directory, just the directories. To quote Greg Stein: "But a recursive revert on a directory could revert a whole lot more than you might think (toss all local mods to all files and dirs under it)." The net result, assuming that's applicable, would be the complete destruction of my working copy. Oops.
-
Petrucio almost 12 years@Rushyo: Indeed you are correct. I wanted to revert everything including files, but on my cursory glance I did not properly read the entire question.
-
Rushyo over 11 yearsSince the mods refuse to remove this: *** DO NOT DO THIS IF YOU HAVE MY ISSUE OR YOU WILL DESTROY YOUR WORKING COPY ***
-
Rushyo over 10 yearsIn case we needed any more proof that people up-vote based on prettiness over code that actually works. Wow.
-
javajavajavajavajava over 10 years@Rushyo There's no need to be so upset about this answer. If it didn't solve your problem then don't mark it as the answer - no need to request it be removed or provide snarky remarks. You did not explain your issue well enough. You should have explained that you don't want to REVERT files, instead you said that you didn't want to TOUCH files (ie. Change the file's timestamp). It's quite obvious this command recursively reverts everything under a directory.
-
Rushyo over 10 years/EDIT You know what, I'm not even going to bother replying to that.
-
Interarticle over 10 yearsUnfortunately, this is what turns up first when you search for
svn revert recursively
on Google, in which case this answer is the correct one. I suggest changing the question title if possible.