Exporting Only changed files from subversion maintaining directory structure

a 夏天 提交于 2019-11-29 04:16:53
Joe

I realize this is a very old question, but answering here will help people searching on google like myself:

svn status | grep '^[ADMR]' | cut -b 8- | xargs -I '{}' cp --parents {} /temporary/destination/dir

As this is one of the first results on Google for exporting only changed files with SVN, I've made a batch version for Windows. Not very sophisticated, as I rarely need to do something in batch, but it should do the job. You do need the svn.exe in your path for this to work. Also take care to include the trailing back slashes in the directory variables.

@echo off
set maindir=C:\path\to\project\root\
set exportdir=C:\path\to\project\export\

:: Delete the export dir and create it again to get rid of the old files
rd %exportdir% /S /Q
md %exportdir%

:: Go to the svn directory
cd %maindir%

:: Go through all "svn status" results
FOR /f "tokens=*" %%G IN ('svn status') DO (call :copyfile "%%G")
GOTO :eof

:: Copy the files to the export directory
:copyfile
    :: We can't directly substr the file name, so we need to buffer it
    set line=%1

    :: substr the correct file name (character 9 to one before the end of the string)
    set filepath=%line:~9,-1%

    :: Copy the file (the asterisk means that it won't ask if directory or file)
    xcopy %maindir%%filepath% %exportdir%%filepath%* /H
    GOTO :eof

The Linux command is a bit shorter. Either use the one as seen in Joe's answer, or this even shorter one (found here):

svn status | cut -c9-99999 | cpio -pvdmu /path/to/export

BASH

Let's say you have a dev server, with SVN, but on your production server you have no SVN. So you dev, and SVN export, and upload the exported site to production.

Now you make changes, but you don't want to rsync/upload entire export - just the changes.

On Dev server:

( assuming you checked out dev site with svn checkout https://svn.server.com/web/sitename/trunk /path/to/sitename and assuming dev site files are at HEAD )

cd /path/to/sitename/
zip /path/to/diff.zip $(svn diff --summarize -r 123:HEAD https://svn.server.com/web/sitename/trunk | awk '{ print $2 }' |  sed -e 's{https://svn.server.com/web/sitename/trunk/{{')

This will create a ZIP file with the changed file[s] - in an intact directory structure - from revision 123:HEAD.

If for some reason you don't want HEAD, then :

cd /path/to/sitename/
svn up -r:124
zip /path/to/diff.zip $(svn diff --summarize -r 123:124 https://svn.server.com/web/sitename/trunk | awk '{ print $2 }' |  sed -e 's{https://svn.server.com/web/sitename/trunk/{{')
svn up

( this sets the DEV to desired revision, grabs file[s], then ups back to HEAD )

No, it is not possible. You can either export the entire repository at that revision, or just the changed files with the path flattened.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!