开发者

Clean an svn checkout (remove non-svn files)

开发者 https://www.devze.com 2023-02-01 09:40 出处:网络
Id like to remove all files in my working copy that are not known in the svn repository. Effectively as if I\'d just made a clean checkout, but Id rather not have to re-download all files.

Id like to remove all files in my working copy that are not known in the svn repository.

Effectively as if I'd just made a clean checkout, but Id rather not have to re-download all files.

The closest think I've come to this is...

rm -rf `svn st | grep "^?" | cut -d" " -f8`

But this seems clunky and I don't totally trust it since inconsistency in output could remove dirs outside svn.

"svn export" isn't what Im looking for because I'm not cleaning the source to package it, I just want to remove cruft mostly (*.pyc, *.orig, *.rej, svn-commit.tmp, *.swp).

Is there a better way to do this 开发者_如何学运维besides making a clean checkout?


Most solutions that are posted here fail to handle folders with whitespaces. This is why we use this one:

svn status --no-ignore | grep '^[?I]' |  sed "s/^[?I] //" | xargs -I{} rm -rf "{}"


http://www.cuberick.com/2008/11/clean-up-your-subversion-working-copy.html

Here is what I do when I want my working copy to be identical to the repo:

 svn st | awk '{print $2}' | xargs rm -rf

That will remove all files that are out of sync with the repository. Then simply update to restore things you deleted and get up to date.

svn up

... Make sure that you've no edits or adds! Safer command might be:

svn st | grep '?' | awk '{print $2}' |xargs rm -f

... What about ignored files? E.g.

svn st --no-ignore
svn st --no-ignore | awk '{print $2}' | xargs rm -rf
svn st --no-ignore | grep '?' | awk '{print $2}' |xargs rm -f


svn status --no-ignore | grep '^[?I]' | awk '{print $2}' | xargs rm -rf

Let me explain.

Get the status of the files in a repository and prints them out one by one to standard output into an array

svn status

This includes files set to normally be ignored by svn

--no-ignore

Match lines that include either a ? or a I as a status. I means an ignored file and ? means a file not under svn control.

| grep '^[?I]'

This prints the second variable in the array which is the filename

| awk '{print $2}'

This removes the files with the printed filesnames

| xargs rm -rf

Cheers, Loop


Use this:

svn status --no-ignore | grep ^I | awk '{print $2}' | xargs rm -rf

Obtained from commandlinefu.


Delete every file that doesn't have the readonly attribute? Make sure you don't have things checked out beforehands...

0

精彩评论

暂无评论...
验证码 换一张
取 消