如何确定根目录中最新的 SVN 修订号?

发布于 2024-07-04 06:35:22 字数 797 浏览 7 评论 0原文

我想开始使用最新的 SVN 修订号来标记我部署的二进制文件。

但是,由于 SVN 是基于文件而不是基于目录/项目,因此我需要扫描所有目录和子目录的文件以确定最高修订号。

在根目录上使用 svn info 不起作用(它只报告该目录的版本,而不是子目录中的文件):

我想知道是否有使用 svn 的快捷方式> 命令来执行此操作。 否则,任何人都可以建议一个网络高效的简单脚本(我更希望它根本不访问远程服务器)?

我还了解一种替代方法是使用 svn:keywords 保留版本文件。 这是可行的(我已经在其他项目中使用过它),但是我厌倦了处理确保文件是脏的以及处理不可避免的合并冲突。

回答我发现我的问题在于在根目录中调用svn info之前没有执行正确的svn up

$ svn info
Path: .
...
Last Changed Author: fak
Last Changed Rev: 713
Last Changed Date: 2008-08-29 00:40:53 +0300 (Fri, 29 Aug 2008)

$ svn up
At revision 721.

$ svn info
Path: .
...
Revision: 721
Last Changed Author: reuben
Last Changed Rev: 721
Last Changed Date: 2008-08-31 22:55:22 +0300 (Sun, 31 Aug 2008)

I would like to start tagging my deployed binaries with the latest SVN revision number.

However, because SVN is file-based and not directory/project-based, I need to scan through all the directory's and subdirectory's files in order to determine the highest revision number.

Using svn info on the root doesn't work (it just reports the version of that directory, not files in subdirectories):

I was wondering if there is a shortcut using the svn command to do this. Otherwise, can anyone suggest a simple script that is network-efficient (I would prefer if it didn't hit the remote server at all)?

I also understand that one alternative approach is to keep a version file with the svn:keywords. This works (I've used it on other projects), but I get tired of dealing with making sure the file is dirty and dealing with the inevitable merge conflicts.

Answer I see my problem lied with not doing a proper svn up before calling svn info in the root directory:

$ svn info
Path: .
...
Last Changed Author: fak
Last Changed Rev: 713
Last Changed Date: 2008-08-29 00:40:53 +0300 (Fri, 29 Aug 2008)

$ svn up
At revision 721.

$ svn info
Path: .
...
Revision: 721
Last Changed Author: reuben
Last Changed Rev: 721
Last Changed Date: 2008-08-31 22:55:22 +0300 (Sun, 31 Aug 2008)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

傲鸠 2024-07-11 06:35:22

单程。 查看代码时,看svn输出的最后一行:

$ svn up
...stuff...
Updated to revision 66593.

更直接的方法:

$ svn info
Path: .
URL: https://svn.example.com/svn/myproject/trunk
Repository Root: https://svn.example.com/svn/
Repository UUID: d2a7a951-c712-0410-832a-9abccabd3052
Revision: 66593
Node Kind: directory
Schedule: normal
Last Changed Author: bnguyen
Last Changed Rev: 66591
Last Changed Date: 2008-09-11 18:25:27 +1000 (Thu, 11 Sep 2008)

One way. When you check out the code, look at the last line of svn output:

$ svn up
...stuff...
Updated to revision 66593.

A more direct way:

$ svn info
Path: .
URL: https://svn.example.com/svn/myproject/trunk
Repository Root: https://svn.example.com/svn/
Repository UUID: d2a7a951-c712-0410-832a-9abccabd3052
Revision: 66593
Node Kind: directory
Schedule: normal
Last Changed Author: bnguyen
Last Changed Rev: 66591
Last Changed Date: 2008-09-11 18:25:27 +1000 (Thu, 11 Sep 2008)
冷默言语 2024-07-11 06:35:22

svnversion 似乎最干净的方法是:

svnversion -c /path/to/your-projects-local-working-copy/. | sed -e 's/[MS]//g' -e 's/^[[:digit:]]*://'

上面的命令将从输出中清除所有 M 和 S 字母(表示本地修改或切换),以及较小的修订号,以防 svnversion 返回范围而不是仅一个修订号(请参阅文档了解更多信息) 。 如果您不想过滤输出,请删除该命令的管道和 sed 部分。

如果您想使用svn info,则还需要使用“递归”(-R) 参数来从所有子目录获取信息。 由于输出随后变成一个长列表,因此您需要进行一些过滤,以从所有最高的版本号中获取最后更改的版本号:

svn info -R /path/to/your-projects-local-working-copy/. | awk '/^Last Changed Rev:/ {print $NF}' | sort -n | tail -n 1

该命令的作用是获取包含字符串 < 的所有行。 code>“Last Changed Rev”,然后删除除最后一个字段(即版本号)之外的每一行中的所有内容,然后按数字对这些行进行排序并删除除最后一行之外的所有内容,从而仅得到最高版本数字。 例如,如果您运行的是 Windows,我相信您也可以在 PowerShell 中轻松完成此操作。

需要明确的是:上述方法可以让您获得本地工作副本所代表的存储库中路径的递归上次更改版本号(对于该本地工作副本),而无需访问服务器。 因此,如果有人在您上次 svn update 后将此路径中的某些内容更新到存储库服务器上,则不会反映在此输出中。

如果您想要的是服务器上此路径的最后更改版本,您可以执行以下操作:

svn info /path/to/your-projects-local-working-copy/.@HEAD | awk '/^Last Changed Rev:/ {print $NF}'

svnversion seems to be the cleanest way to do this:

svnversion -c /path/to/your-projects-local-working-copy/. | sed -e 's/[MS]//g' -e 's/^[[:digit:]]*://'

The above command will clean out any M and S letters (indicating local modifications or switchedness) from the output, as well as the smaller revision number in case svnversion returns a range instead of just one revision number (see the docs for more info). If you don't want to filter the output, take out the pipe and the sed part of that command.

If you want to use svn info, you need to use the "recursive" (-R) argument to get the info from all of the subdirectories as well. Since the output then becomes a long list, you'll need to do some filtering to get the last changed revision number from all of those that is the highest:

svn info -R /path/to/your-projects-local-working-copy/. | awk '/^Last Changed Rev:/ {print $NF}' | sort -n | tail -n 1

What that command does is that it takes all of the lines that include the string "Last Changed Rev", then removes everything from each of those lines except the last field (i.e. the revision number), then sorts these lines numerically and removes everything but the last line, resulting in just the highest revision number. If you're running Windows, I'm sure you can do this quite easily in PowerShell as well, for example.

Just to be clear: the above approaches get you the recursive last changed revision number of just the path in the repo that your local working copy represents, for that local working copy, without hitting the server. So if someone has updated something in this path onto the repository server after your last svn update, it won't be reflected in this output.

If what you want is the last changed revision of this path on the server, you can do:

svn info /path/to/your-projects-local-working-copy/.@HEAD | awk '/^Last Changed Rev:/ {print $NF}'
只是偏爱你 2024-07-11 06:35:22

此问题重复。 正如我在那里发布的,svnversion 命令是您的朋友。 无需解析输出,无需先更新,只需完成工作即可。

Duplicate of this question. As I posted there, the svnversion command is your friend. No need to parse the output, no need to update first, just does the job.

聊慰 2024-07-11 06:35:22

我不知道您是否使用 MSBuild(Visual Studio) 来构建二进制文件。
但如果你愿意:
Subverion 和 MSBuild 之间可以通过以下方式建立连接
MSBuild 社区任务项目

这是我们构建脚本的一部分:我们的 (C#) 应用程序获取包含的 svn 修订号:

  <SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="installationpath\of\subversion\bin">
     <Output TaskParameter="Revision" PropertyName="Revision" />
  </SvnVersion>
  <Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>
...
    AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
     AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"

I don't know if you are using MSBuild(Visual Studio) to build your binaries.
But if you would:
there is a connection possible between Subverion and MSBuild through
MSBuild Community Tasks Project

Here's part of our build script: our (C#) application gets the svn revision number included:

  <SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="installationpath\of\subversion\bin">
     <Output TaskParameter="Revision" PropertyName="Revision" />
  </SvnVersion>
  <Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>
...
    AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
     AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"

Jan

琉璃梦幻 2024-07-11 06:35:22

@Charles Miller 和 @Troels Arvin 提供的答案是正确的 - 您可以使用 svn updatesvn info 的输出,但正如您所暗示的那样,后者仅有效如果存储库是最新的。 话又说回来,如果源树的一部分与其他部分处于不同的修订版上,我不确定任何修订号对您来说会有什么价值。 在我看来,你确实应该在同构树上工作。
我建议在运行 info 之前进行更新(或者如果您已经更新了构建,那么您就很幸运)或使用 svn info URL-to-source 。

The answers provided by @Charles Miller and @Troels Arvin are correct - you can use the output of the svn update or svn info, but as you hint, the latter only works if the repository is up to date. Then again, I'm not sure what value any revision number is going to be to you if part of your source tree is on a different revision than another part. It really sounds to me like you should be working on a homogeneous tree.
I'd suggest either updating before running info (or if you've already updated for your build, you're golden) or using svn info URL-to-source.

醉殇 2024-07-11 06:35:22

有一个随 Subversion 一起发布的程序,名为 svnversion ,它的功能完全符合您的要求想做。 这就是我们标记网站的方式。

There is a program distributed with Subversion called svnversion that does exactly what you want to do. It's how we tag our websites.

來不及說愛妳 2024-07-11 06:35:22

如果您只想要已提交的最新更改的修订号,并且使用的是不带 grep/awk/xargs 的 Windows,则可以运行以下基本命令(命令行):

X:\trunk>svn info -r COMMITTED | for /F "tokens=2" %r in ('findstr /R "^Revision"') DO @echo %r
67000

svn info -r COMMITTED 将为您提供对当前所在目录的最新提交更改:

X:\Trunk>svn info -r COMMITTED
Path: trunk
URL: https://svn.example.com/svn/myproject/trunk
Repository Root: https://svn.example.com/svn/
Repository UUID: d2a7a951-c712-0410-832a-9abccabd3052
Revision: 67400
Node Kind: directory
Last Changed Author: example
Last Changed Rev: 67400
Last Changed Date: 2008-09-11 18:25:27 +1000 (Thu, 11 Sep 2008)

for 循环运行 findstr 来定位 svn info 输出的修订部分。 其输出将是(您不会看到这个):

Revision: 67000

然后分割 令牌,并返回第二个,将被回显:

67000

If you just want the revision number of the latest change that was committed, and are using Windows without grep/awk/xargs, here is the bare-bones command to run (command line):

X:\trunk>svn info -r COMMITTED | for /F "tokens=2" %r in ('findstr /R "^Revision"') DO @echo %r
67000

svn info -r COMMITTED will give you the latest committed change to the directory you are currently in:

X:\Trunk>svn info -r COMMITTED
Path: trunk
URL: https://svn.example.com/svn/myproject/trunk
Repository Root: https://svn.example.com/svn/
Repository UUID: d2a7a951-c712-0410-832a-9abccabd3052
Revision: 67400
Node Kind: directory
Last Changed Author: example
Last Changed Rev: 67400
Last Changed Date: 2008-09-11 18:25:27 +1000 (Thu, 11 Sep 2008)

The for loop runs findstr to locate the Revision portion of the output from svn info. The output from this will be (you won't see this):

Revision: 67000

Which then splits the tokens, and returns the 2nd, to be echoed out:

67000
你不是我要的菜∠ 2024-07-11 06:35:22

“svn info”将显示工作副本的修订号(请参阅“svn info”输出中的“修订”行)。 您的构建系统可能允许您将“svn info”输出的相关部分放置在将反映在您的应用程序中的某个位置。 例如,您可以指定在构建时应创建一个临时(无版本)文件,其中包含“svn info”的输出; 然后在编译时包含该文件。

"svn info" will show you the working copy's revision number (see the "Revision" line in the output from "svn info"). Your build system probably allows you to place the relevant part of "svn info"'s output somewhere where it will be reflected in your application. For example, you may specify that when building, a temporary (un-versioned) file should be created, containing output from "svn info"; and you then include this file when compiling.

淡写薰衣草的香 2024-07-11 06:35:22

对我来说,找出主干/分支的最后修订号的最佳方法是从远程 URL 获取它。 重要的是不要使用工作目录,因为它可能已过时。 这是一个带有批处理的片段(我非常讨厌;-)):

@for /f "tokens=4" %%f in ('svn info %SVNURL% ^|find "Last Changed Rev:"') do set lastPathRev=%%f

echo trunk rev no: %lastPathRev%

尽管如此,我还是有一个问题,要将这个数字作为临时版本硬编码到包含 $Rev:$ 的源中。 问题是 $Rev:$ 包含文件 rev. 不。 因此,如果主干版本号大于版本文件的版本号,我需要“人为”修改此文件并提交它以获得正确的临时版本(=主干版本)。 这是一块窗格! 有人有更好的主意吗?
非常感谢

For me the best way to find out the last revision number of the trunk/branch is to get it from the remote URL. It is important NOT to use the working dir because it may be obsolete. Here is a snippet with batch ( I hate a much ;-)):

@for /f "tokens=4" %%f in ('svn info %SVNURL% ^|find "Last Changed Rev:"') do set lastPathRev=%%f

echo trunk rev no: %lastPathRev%

Nevertheless I have a problem to hardcode this number as interim version into sources containing $Rev:$. The problem is that $Rev:$ contains the file rev. no. So if trunk rev no is larger then the rev no of version file, I need to modify this file "artificially" and to commit it to get the correct interim version (=trunk version). This is a pane! Does somebody has better idea?
Many thanks

九命猫 2024-07-11 06:35:22

这很荒谬,但 svn info 或 svnversion 不会考虑子目录; 这是一个称为工作“混合修订”的功能 - 我称之为折磨。 我只需要找到实时代码库的最新“修订版”,下面的破解方法对我有用 - 可能需要一段时间才能运行:

repo_root# find ./ | xargs -l svn info  | grep 'Revision: ' | sort
...
Revision: 86
Revision: 86
Revision: 89
Revision: 90
root@fairware:/home/stage_vancity#

This is ridiculous but svn info or svnversion wont take into consideration subdirectories; it's a feature called working 'Mixed Revisions' - I call it torture. I just needed to find the latest 'revision' of the live codebase and the hacked way below worked for me - it might take a while to run:

repo_root# find ./ | xargs -l svn info  | grep 'Revision: ' | sort
...
Revision: 86
Revision: 86
Revision: 89
Revision: 90
root@fairware:/home/stage_vancity#
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文