开发者

Getting the current Revision number on command line via TortoiseSVN

I'm trying to write a batch file in which I need the HEAD revision of the project I am working on.

Is there a command to get this from the command开发者_如何学C line?

I am on a Windows XP Machine.

EDIT I ended up using a mix between Shambulator, mizipzor, and Stefan's answers. I ended up with this:

for /f "tokens=5" %%i in ('SubWCRev WorkingCopyPath^|find "Last committed at revision"') do set version=%%i 
echo %version%

Thanks for all your help guys

Added this answer to the list below as well.


It's awkward without the text-processing capabilities of *nix, but this batch file does it:

@echo off
for /f "tokens=2" %%i in ('svn info -rHEAD svn://localhost^|find "Revision"') do @echo %%i

Substitute your svn repository for my svn://localhost.

svn info gets the repository info, then pipes it to find, which strips out everything except the line containing the revision number. The for command gives you the second "token" on that line (the first one is Revision:).

EDIT: As others have mentioned already, you'll need a command-line version of Subversion installed, and have svn.exe on your PATH.


If you need that revision in a file, use SubWCRev which is installed with TortoiseSVN (or available separately).


I ended up using a mix between Shambulator, mizipzor, and Stefan's answers. I ended up with this:

for /f "tokens=5" %%i in ('SubWCRev WorkingCopyPath^|find "Last committed at revision"') do set version=%%i  
echo %version% 

Thanks for all your help guys


TortoiseSVN doesn't give you any command-line interface as it is just a shell extension.

However, if you install the svn command-line tools, the following command will give you details of the SVN URL:

svn info [SVN-URL]

to extract the revision you could use this:

svn info [SVN-URL] | grep Revision | awk '{print $2}'

(that is assuming you've got some UNIX tools installed, e.g. cygwin)


The current answers list how to print the current revision on the central svn repository. If you're interested in the current local checked out revision I found this blog post that does something quite similar to what is done in Shambulator's answer:

@echo off
FOR /F "tokens=2 skip=4" %%G IN ('svn info --revision HEAD') DO ^
IF NOT DEFINED REVISION SET REVISION=%%G
echo %REVISION%


I know this question is old, but it was just what I was looking for, only problem was that I couldn't get the answer to work. Here's the bat script I ended up with:

set SubWCRev=C:\Program Files\TortoiseSVN\bin\SubWCRev.exe
set WorkingCopyPath=%~dp0
for /f "tokens=5" %%i in ('""%SubWCRev%" "%WorkingCopyPath%.""') do set version=%%i
@echo Version=%version%

I used the directory that the bat file was located in as the SVN reporitory folder, use %~dp1 is you want to pass in the directory as a parameter


I don't think there's any way of doing this directly from the command line using tortoisesvn. You can install the command line version from Collabnet and then use a command such as this:

c:\>svn ls -v svn://server/Source
67336 user1                Jul 05 13:00 ./
67336 user1                Jul 05 13:00 Source/


Another possible approach. If you've got the repository checked out then the .svn\entries file has the revision number in the 4th line. i.e.

head -4 entries | tail -1

will give you the revision number.

probably not all that wise to use this as the format of the file could change - it really depends on if the script is just for personal use


svn info -rHEAD %cd%|find "Revision:"> %temp%\__svnrev.tmp
set /p revision=< %temp%\__svnrev.tmp
del %temp%\__svnrev.tmp
set revision=%revision:~10%
echo %revision%

change %cd% in first line to your desired path


Here is my variant of shambulator's answer, in case you don't have svn.exe in the PATH. Note the use of backquotes to handle the spaces in the path.

@echo off
set SVN_EXE=C:\Program Files (x86)\VisualSVN\bin\svn.exe

rem Find revision of entire repository
for /f "usebackq tokens=2" %%i in (`call "%SVN_EXE%" info -rHEAD https://svnroot/repo^|find "Revision"`) do @echo %%i

rem Find revision of a path in the repository
for /f "usebackq tokens=4" %%i in (`call "%SVN_EXE%" info -rHEAD https://svnroot/repo/project/trunk^|find "Last Changed Rev"`) do @echo %%i


This seems easier than all the previous answers:

svnlook youngest <repo-path>

It returns a single revision number.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜