How is possible to compare two folders in SVN and export the differences to another folder in windows command prompt?
With tortoise svn gui, we can compare two URLS select all and export selection files to a folder. As mentioned in export changed files using tortoise svn to another directory.
Is it possible to do it from command prompt ?!
I see list of commands at https://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-automation.html but could not find any thing.
I find an script at https://www.electrictoolbox.com/subversion-export-changed-files-cli/ but it with was for the linux,
答案 0 :(得分:1)
我更改了您提到的shell script for Linux以使用Windows。第一个变体(svn-export.bat
)在存储库中使用两个不同的修订版。第二个变体(svn-localexport.bat
)将与两个本地目录一起使用。
它使用svn diff --summarize -r revision-from:revision-to repository
作为svn命令来工作。创建批处理文件:svn-export.bat
将以下内容复制到其中并按以下方式使用:
svn-export revision-from revision-to repository target-directory
<强> SVN-export.bat:强>
@echo off
setlocal enabledelayedexpansion
set INVARGS=0
if [%1] == [] set INVARGS=1
if [%2] == [] set INVARGS=1
if [%3] == [] set INVARGS=1
if [%4] == [] set INVARGS=1
if %INVARGS% == 1 (
echo Usage: %0 ^<revision_from^> ^<revision_to^> ^<repository^> ^<target_directory^>"
goto eof
)
rem set up nice names for the incoming parameters to make the script more readable
set "revision_from=%1"
set "revision_to=%2"
set "repository=%3"
set "target_directory=%~4"
rem the findstr is needed so we only get added/modified files and not the deleted ones or anything else
set "svnCommand=svn diff --summarize -r%revision_from%:%revision_to% %repository% ^| findstr /B "[AM]""
if not exist "%target_directory%" ( mkdir "%target_directory%" )
rem go into target directory
pushd "%target_directory%"
for /f "delims=" %%L in ('%svnCommand%') do (
rem convert line like: "A http://..." to "http://..."
set "filename=%%L"
rem echo.before: ^<!filename!^>
set "find=*%repository%/"
call set filename=%%filename:!find!=%%
rem echo.after: ^<!filename!^>
rem don't export if it's a directory we've already created
if not exist "!filename!" (
for %%F in ("!filename!") do set "directory=%%~dpF"
if not exist "!directory!" ( mkdir "!directory!" )
svn export -r %revision_to% %repository%/!filename! "%cd%\!filename!"
)
)
popd
rem to summarize any deleted files or directories at the end of the script uncomment the following lines
rem echo.Deleted files:
rem svn diff --summarize -r%revision_from%:%revision_to% %repository% | findstr /B "[D]"
:eof
下一个脚本几乎相同,但它比较了由svn管理的两个本地目录。因此,它使用:svn diff --summarize --old folder-old --new folder-new
作为svn命令。通过以下方式使用它:
svn-localexport folder-old folder-new target-directory
<强> svn_localexport.bat:强>
@echo off
setlocal enabledelayedexpansion
set INVARGS=0
if [%1] == [] set INVARGS=1
if [%2] == [] set INVARGS=1
if [%3] == [] set INVARGS=1
if %INVARGS% == 1 (
echo Usage: %0 ^<folder_old^> ^<folder_new^> ^<target_directory^>"
goto eof
)
rem set up nice names for the incoming parameters to make the script more readable
set "folder_old=%~1"
set "folder_new=%~2"
set "target_directory=%~3"
pushd "%folder_old%"
set "folder_old_abs=%cd%"
popd
pushd "%folder_new%"
set "folder_new_abs=%cd%"
popd
rem the findstr is needed so we only get added/modified files and not the deleted ones or anything else
set "svnCommand=svn diff --summarize --old "%folder_old_abs%" --new "%folder_new_abs%" ^| findstr /B "[AM]""
if not exist "%target_directory%" ( mkdir "%target_directory%" )
rem go into target directory
pushd "%target_directory%"
for /f "delims=" %%L in ('%svnCommand%') do (
rem convert line like: "A C:\Users\...\src.c" to "src.c"
set "filename=%%L"
rem echo.before: ^<!filename!^>
set "find=*%folder_old_abs%\"
call set filename=%%filename:!find!=%%
rem echo.after: ^<!filename!^>
rem don't export if it's a directory we've already created
if not exist "!filename!" (
for %%F in ("!filename!") do set "directory=%%~dpF"
if not exist "!directory!" ( mkdir "!directory!" )
echo copy "%folder_new_abs%\!filename!" "%cd%\!filename!"
copy "%folder_new_abs%\!filename!" "%cd%\!filename!"
)
)
popd
rem to summarize any deleted files or directories at the end of the script uncomment the following lines
rem echo.Deleted files:
rem svn diff --summarize --old "%folder_old_abs%" --new "%folder_new_abs%" | findstr /B "[D]"
:eof
请注意,如果目标文件已存在,则两个批处理脚本都不会覆盖它们。如果要更改,请删除相应的if语句。