简体   繁体   English

获取 SVN 修订号到批处理文件变量

[英]Get SVN revision number to batch file variable

Want to get last changed revision from svn branch in batch file.想要从批处理文件中的 svn 分支获取最后更改的修订版。

echo on
set svnUrl=%1
set releaseName=%2
set buildNumber=%3


for /f %%i in ('svn info  %svnUrl%/branches/%releaseName% -r HEAD ^| FINDSTR "^Last.Changed.Rev:"') do set revisionNumber=%%i
echo %revisionNumber%

But I'm getting word Last instead of Last Changed Rev: 10但是我得到的是 Last 而不是 Last Changed Rev: 10

In console for command在控制台中输入命令

D:\svn info http://desktop-24i22vk:81/svn/Test/branches/TST-1 -r HEAD

I'm receiving console output:我收到控制台输出:

Path: TST-1
URL: http://desktop-24i22vk:81/svn/Test/branches/TST-1
Relative URL: ^/branches/TST-1
Repository Root: http://desktop-24i22vk:81/svn/Test
Repository UUID: 57a8baac-304e-e54b-94b3-b7d049dce932
Revision: 17
Node Kind: directory
Last Changed Author: import
Last Changed Rev: 10
Last Changed Date: 2016-07-22 15:26:37 +0200 (pá, 22 čvc 2016)

I want to get last changed revision number, here it's 10. I was thinking to store whole line text Last Changed Rev: 10 to variable and then replace text to get only number.我想获得最后更改的修订号,这里是 10。我想将整行文本 Last Changed Rev: 10 存储到变量,然后替换文本以仅获取数字。 I would appreciate even other (windows batch) approaches how to get it.我什至会欣赏其他(Windows 批处理)方法如何获得它。 Thanks谢谢

The default behavior of FOR /F is to break each line into tokens, delimited by spaces and/or tabs, and return only the first token of each line. FOR /F 的默认行为是将每一行分成标记,以空格和/或制表符分隔,并仅返回每行的第一个标记。 That explains why you are only getting "Last".这解释了为什么你只得到“最后”。

You could preserve the entire line by setting the delims option to nothing您可以通过将 delims 选项设置为空来保留整行

for /f "delims=" %%i ...

But you don't want the entire line.但你不想要整条线。 You just want the last (4th) token.您只需要最后一个(第 4 个)令牌。 So ...所以...

for /f "tokens=4" %%i ...

可以使用svn info -r HEAD --show-item revision来仅获取 Head rev 作为输出...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从SVN命令行中提取文件的修订号 - Extracting the Revision number of a file from the SVN Command line Windows批处理文件中来自远程存储库的svn head修订-系统找不到指定的文件 - svn head revision from a remote repository in windows batch file - the system cannot find the file specified 如何在Windows批处理文件的变量中获取目录中的文件数 - How to get the number of files in directory in variable in windows batch file SVN:如何知道文件在哪个版本中被删除? - SVN: How to know in which revision a file was deleted? 使用可变数量的参数调用批处理文件 - Call batch file with variable number of arguments 以编程方式更新具有SVN修订号的MFC应用程序中的FILEVERSION - Programmatically updating FILEVERSION in a MFC app w/SVN revision number 如何在批处理文件中的变量中获取文件的位置? - How to get the location of a file in a variable in a batch file? 在编译时在Windows应用程序中嵌入SVN修订版号 - Embedding SVN Revision number at compile time in a Windows app 在工作副本修订版上将链接复制/粘贴到SVN上的文件 - Copy/paste link to file on SVN at working copy revision 命令行帮助:将文件更新到SVN / Subversion中的特定旧版本? - Command line help for : Updating a file to a specific older revision in SVN /Subversion?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM