始终使用SVN提交相同的文件

时间:2021-05-18 15:21:25

In my web application I have a file which hold the current revision number via $Rev$. This work fine except, if I don't make any changes to that file, it doesn't get committed.

在我的Web应用程序中,我有一个文件,它通过$ Rev $保存当前的修订版号。这项工作正常,但是,如果我不对该文件进行任何更改,则不会提交。

Is there anyway I can force a single file to always get committed to the SVN server?

无论如何我是否可以强制单个文件始终提交到SVN服务器?

I'm using TortoiseSVN for Windows so any code or step-by-step instructions would be helpful.

我正在使用TortoiseSVN for Windows,因此任何代码或分步说明都会有所帮助。

13 个解决方案

#1


9  

If you have TortoiseSVN installed, you also have the SubWCRev tool available. Use that tool to get the revision instead of misusing the $REV$ keyword.

如果安装了TortoiseSVN,则还可以使用SubWCRev工具。使用该工具获取修订版,而不是滥用$ REV $关键字。

  1. create a template file which contains your defines, maybe something like

    创建一个模板文件,其中包含您的定义,可能是类似的

    const long WC_REV = $WCREV$;

    const long WC_REV = $ WCREV $;

    in a file named version.h.tmpl

    在名为version.h.tmpl的文件中

  2. on every build, call SubWCRev to create the 'real' file you can use in your application:

    在每个构建中,调用SubWCRev来创建可在应用程序中使用的“真实”文件:

    SubWCRev path\to\workingcopy path\to\version.h.tmpl path\to\version.h

    SubWCRev path \ to \ workingcopy path \ to \ version.h.tmpl path \ to \ version.h

This will create the file version.h from version.h.tmpl, with the text $WCREV$ replaced with the revision your working copy is currently at.

这将从version.h.tmpl创建文件version.h,文本$ WCREV $替换为您的工作副本当前所在的修订版本。

The docs for SubWCRev might help too.

SubWCRev的文档也可能有所帮助。

#2


13  

Basically, you want the output of the svnversion command in a file.

基本上,您希望在文件中输出svnversion命令。

Such files are usually kept out of the repository, and automatically created by a build script. I suggest you do the same. If you don't build, but just to a svn up on the server side, just call svnversion after svn up or create a shell script to do both actions.

此类文件通常保留在存储库之外,并由构建脚本自动创建。我建议你这样做。如果你没有构建,只是为了服务器端的svn,只需在svn up之后调用svnversion或者创建一个shell脚本来执行这两个操作。

If you have to keep it in the repository on the other hand, calling svnversion in a pre-commit hook would be your best bet.

另一方面,如果你必须将它保存在存储库中,那么在预提交钩子中调用svnversion将是你最好的选择。

#3


6  

I think you may be not understanding how the $Rev$ flag works. The goal of the Rev flag is not to have this revision always committed into the subversion repository. The goal is that on an update, the Rev flag will always be what the revision is. You should not need to put code into subversion that contains the revision. Subversion is very good at keeping track of that information for you.

我想您可能不了解$ Rev $标志的工作原理。 Rev标志的目标不是始终将此修订提交到subversion存储库。目标是在更新时,Rev标志将始终是修订版本。您不应该将代码放入包含修订版的subversion中。 Subversion非常善于为您跟踪这些信息。

What you probably missed is that, you need to set a property on the file so that the Revision keyword will be properly processed.

您可能错过的是,您需要在文件上设置属性,以便正确处理Revision关键字。

svn propset svn:keywords "Revision" file.txt

This will ensure that whenever you do an update, the $Rev: xxx$ flag will be updated with the current revision. You don't need to worry about how it is committed to the repository.

这将确保无论何时进行更新,$ Rev:xxx $标志都将使用当前版本进行更新。您无需担心它如何提交到存储库。

#4


4  

@gatekiller: It seems TortoiseSVN does support Client Side Hooks.

@gatekiller:似乎TortoiseSVN确实支持客户端钩子。

#5


3  

This work fine except, if I don't make any changes to that file, it doesn't get committed.

这项工作正常,但是,如果我不对该文件进行任何更改,则不会提交。

If the file never changes, why would you need it to commmit every single time?

如果文件永远不会改变,为什么每次都需要它来提交?

[EDIT] @Sean = I understand what he's trying to do, but if the file is never getting updated via a hook or some other process and therefore never changing then SVN will never pick it up.

[编辑] @Sean =我理解他正在尝试做什么,但如果文件永远不会通过钩子或其他进程更新,因此永远不会改变,那么SVN将永远不会接收它。

#6


2  

I suggest changing the approach, commiting a file every time means implicitly keeping the global revision number in that file. There user may need another keyword, GlobalKey, whose inexistance is explained here I actually have not used mentioned svnversion however, it may lead you to a solution.

我建议更改方法,每次提交一个文件意味着隐式地将全局修订号保留在该文件中。用户可能需要另一个关键字GlobalKey,这里解释了其不足之处我实际上没有使用过提到的svnversion,但它可能会引导您找到解决方案。

#7


2  

Could the revision-number file be changed by a script that deploys your website from SVN to the web-server?

可以通过将您的网站从SVN部署到Web服务器的脚本来更改版本号文件吗?

Not sure about on Windows, but using a bash-script, I would do something like..

在Windows上不确定,但使用bash脚本,我会做类似的事情..

$ version=$(svnversion)
$ svn export . /tmp/staging/
Export complete.
$ echo "Revision: ${version}" > /tmp/staging/version.txt

Then /tmp/staging/version.txt would contain "Revision: 1" (or whatever the highest revision number is).

然后/tmp/staging/version.txt将包含“Revision:1”(或任何最高版本号)。

You could of course replace some identifier in a file, like $Rev$ (instead of creating version.txt as per the example above)

您当然可以替换文件中的某些标识符,例如$ Rev $(而不是根据上面的示例创建version.txt)

#8


1  

Depending on your client, some of them offer a pre-commit hook that you can implement something that simply "touches" the file and flags it as changed. If your using something like Visual Studio you could create a post build task that would "touch" the file but you would have to make sure that you do a build before committing changes.

根据您的客户端,其中一些提供了一个预提交挂钩,您可以实现一些简单地“触摸”文件并将其标记为已更改的内容。如果您使用像Visual Studio这样的东西,您可以创建一个“触摸”文件的后期构建任务,但是您必须确保在提交更改之前进行构建。

#9


1  

@gradonmantank: Because he wants that file to be updated with the latest revision number. Did you read his question completely?

@gradonmantank:因为他希望用最新的版本号更新该文件。你完全读过他的问题吗?

The pre-commit hook might work.

预提交挂钩可能有效。

#10


1  

I used to have a manual way of doing that. I'd run a script that would use sed to replace a comment with the current timestamp in my $Rev$ file. That way, the file contents would change and Subversion would commit it.

我曾经有过一种手工方式。我将运行一个脚本,使用sed将注释替换为$ Rev $文件中的当前时间戳。这样,文件内容就会改变,Subversion会提交它。

What I didn't do was to take that to the next step: using Subversion's repository hooks to automate the process. Trouble is, I'm not sure if you're allowed to change file contents in hooks. The documentation seems to suggest that you can't.

我没做的是将其用于下一步:使用Subversion的存储库挂钩来自动化该过程。麻烦的是,我不确定你是否允许更改钩子中的文件内容。文档似乎暗示你不能。

Instead, I guess you'd need a little script that you'd execute in place of the svn commit command that first updates the timestamp and then runs the normal commit.

相反,我猜你需要一个小脚本来代替svn commit命令执行,该命令首先更新时间戳,然后运行正常提交。

#11


1  

Comitting the file wouldn't do you any good. The file isn't committed with the full version inside, it is replaced with just the keyword. If you look at the file inside the repository you will see this.

编写文件对你没有任何帮助。该文件未在内部提交完整版本,仅替换为关键字。如果你查看存储库中的文件,你会看到这个。

As such, you need to force the file to be updated in some way instead.

因此,您需要强制以某种方式更新文件。

If you're on the Windows platform, you can use the SubWCRev tool, distributed with TortoiseSVN. Documentation here.

如果您使用的是Windows平台,则可以使用随TortoiseSVN一起分发的SubWCRev工具。文档在这里。

#12


1  

You can use svn pre-commit-hooks to do it.
The general idea I have in mind is create one that before the commit will put the new revision number in the file (get it using svnlook) or maybe change a bogus property on the file (it has to change or SVN will ignore it).

您可以使用svn pre-commit-hooks来完成它。我想到的一般想法是创建一个在提交之前将新版本号放入文件(使用svnlook获取)或者可能更改文件上的伪属性(它必须更改或SVN将忽略它)。

For more information about pre-commit-hooks I found this page useful.

有关预提交挂钩的更多信息,我发现此页面很有用。

#13


1  

I think the best approach to ensuring that there is a file in your web application that has the SVN revision number is to not have a file you commit, but rather to extract it as part of your build script.

我认为确保Web应用程序中存在具有SVN修订号的文件的最佳方法是不提交您提交的文件,而是将其作为构建脚本的一部分提取。

If you use maven, you can do this with the maven-buildnumber-plugin.

如果您使用maven,则可以使用maven-buildnumber-plugin执行此操作。

#1


9  

If you have TortoiseSVN installed, you also have the SubWCRev tool available. Use that tool to get the revision instead of misusing the $REV$ keyword.

如果安装了TortoiseSVN,则还可以使用SubWCRev工具。使用该工具获取修订版,而不是滥用$ REV $关键字。

  1. create a template file which contains your defines, maybe something like

    创建一个模板文件,其中包含您的定义,可能是类似的

    const long WC_REV = $WCREV$;

    const long WC_REV = $ WCREV $;

    in a file named version.h.tmpl

    在名为version.h.tmpl的文件中

  2. on every build, call SubWCRev to create the 'real' file you can use in your application:

    在每个构建中,调用SubWCRev来创建可在应用程序中使用的“真实”文件:

    SubWCRev path\to\workingcopy path\to\version.h.tmpl path\to\version.h

    SubWCRev path \ to \ workingcopy path \ to \ version.h.tmpl path \ to \ version.h

This will create the file version.h from version.h.tmpl, with the text $WCREV$ replaced with the revision your working copy is currently at.

这将从version.h.tmpl创建文件version.h,文本$ WCREV $替换为您的工作副本当前所在的修订版本。

The docs for SubWCRev might help too.

SubWCRev的文档也可能有所帮助。

#2


13  

Basically, you want the output of the svnversion command in a file.

基本上,您希望在文件中输出svnversion命令。

Such files are usually kept out of the repository, and automatically created by a build script. I suggest you do the same. If you don't build, but just to a svn up on the server side, just call svnversion after svn up or create a shell script to do both actions.

此类文件通常保留在存储库之外,并由构建脚本自动创建。我建议你这样做。如果你没有构建,只是为了服务器端的svn,只需在svn up之后调用svnversion或者创建一个shell脚本来执行这两个操作。

If you have to keep it in the repository on the other hand, calling svnversion in a pre-commit hook would be your best bet.

另一方面,如果你必须将它保存在存储库中,那么在预提交钩子中调用svnversion将是你最好的选择。

#3


6  

I think you may be not understanding how the $Rev$ flag works. The goal of the Rev flag is not to have this revision always committed into the subversion repository. The goal is that on an update, the Rev flag will always be what the revision is. You should not need to put code into subversion that contains the revision. Subversion is very good at keeping track of that information for you.

我想您可能不了解$ Rev $标志的工作原理。 Rev标志的目标不是始终将此修订提交到subversion存储库。目标是在更新时,Rev标志将始终是修订版本。您不应该将代码放入包含修订版的subversion中。 Subversion非常善于为您跟踪这些信息。

What you probably missed is that, you need to set a property on the file so that the Revision keyword will be properly processed.

您可能错过的是,您需要在文件上设置属性,以便正确处理Revision关键字。

svn propset svn:keywords "Revision" file.txt

This will ensure that whenever you do an update, the $Rev: xxx$ flag will be updated with the current revision. You don't need to worry about how it is committed to the repository.

这将确保无论何时进行更新,$ Rev:xxx $标志都将使用当前版本进行更新。您无需担心它如何提交到存储库。

#4


4  

@gatekiller: It seems TortoiseSVN does support Client Side Hooks.

@gatekiller:似乎TortoiseSVN确实支持客户端钩子。

#5


3  

This work fine except, if I don't make any changes to that file, it doesn't get committed.

这项工作正常,但是,如果我不对该文件进行任何更改,则不会提交。

If the file never changes, why would you need it to commmit every single time?

如果文件永远不会改变,为什么每次都需要它来提交?

[EDIT] @Sean = I understand what he's trying to do, but if the file is never getting updated via a hook or some other process and therefore never changing then SVN will never pick it up.

[编辑] @Sean =我理解他正在尝试做什么,但如果文件永远不会通过钩子或其他进程更新,因此永远不会改变,那么SVN将永远不会接收它。

#6


2  

I suggest changing the approach, commiting a file every time means implicitly keeping the global revision number in that file. There user may need another keyword, GlobalKey, whose inexistance is explained here I actually have not used mentioned svnversion however, it may lead you to a solution.

我建议更改方法,每次提交一个文件意味着隐式地将全局修订号保留在该文件中。用户可能需要另一个关键字GlobalKey,这里解释了其不足之处我实际上没有使用过提到的svnversion,但它可能会引导您找到解决方案。

#7


2  

Could the revision-number file be changed by a script that deploys your website from SVN to the web-server?

可以通过将您的网站从SVN部署到Web服务器的脚本来更改版本号文件吗?

Not sure about on Windows, but using a bash-script, I would do something like..

在Windows上不确定,但使用bash脚本,我会做类似的事情..

$ version=$(svnversion)
$ svn export . /tmp/staging/
Export complete.
$ echo "Revision: ${version}" > /tmp/staging/version.txt

Then /tmp/staging/version.txt would contain "Revision: 1" (or whatever the highest revision number is).

然后/tmp/staging/version.txt将包含“Revision:1”(或任何最高版本号)。

You could of course replace some identifier in a file, like $Rev$ (instead of creating version.txt as per the example above)

您当然可以替换文件中的某些标识符,例如$ Rev $(而不是根据上面的示例创建version.txt)

#8


1  

Depending on your client, some of them offer a pre-commit hook that you can implement something that simply "touches" the file and flags it as changed. If your using something like Visual Studio you could create a post build task that would "touch" the file but you would have to make sure that you do a build before committing changes.

根据您的客户端,其中一些提供了一个预提交挂钩,您可以实现一些简单地“触摸”文件并将其标记为已更改的内容。如果您使用像Visual Studio这样的东西,您可以创建一个“触摸”文件的后期构建任务,但是您必须确保在提交更改之前进行构建。

#9


1  

@gradonmantank: Because he wants that file to be updated with the latest revision number. Did you read his question completely?

@gradonmantank:因为他希望用最新的版本号更新该文件。你完全读过他的问题吗?

The pre-commit hook might work.

预提交挂钩可能有效。

#10


1  

I used to have a manual way of doing that. I'd run a script that would use sed to replace a comment with the current timestamp in my $Rev$ file. That way, the file contents would change and Subversion would commit it.

我曾经有过一种手工方式。我将运行一个脚本,使用sed将注释替换为$ Rev $文件中的当前时间戳。这样,文件内容就会改变,Subversion会提交它。

What I didn't do was to take that to the next step: using Subversion's repository hooks to automate the process. Trouble is, I'm not sure if you're allowed to change file contents in hooks. The documentation seems to suggest that you can't.

我没做的是将其用于下一步:使用Subversion的存储库挂钩来自动化该过程。麻烦的是,我不确定你是否允许更改钩子中的文件内容。文档似乎暗示你不能。

Instead, I guess you'd need a little script that you'd execute in place of the svn commit command that first updates the timestamp and then runs the normal commit.

相反,我猜你需要一个小脚本来代替svn commit命令执行,该命令首先更新时间戳,然后运行正常提交。

#11


1  

Comitting the file wouldn't do you any good. The file isn't committed with the full version inside, it is replaced with just the keyword. If you look at the file inside the repository you will see this.

编写文件对你没有任何帮助。该文件未在内部提交完整版本,仅替换为关键字。如果你查看存储库中的文件,你会看到这个。

As such, you need to force the file to be updated in some way instead.

因此,您需要强制以某种方式更新文件。

If you're on the Windows platform, you can use the SubWCRev tool, distributed with TortoiseSVN. Documentation here.

如果您使用的是Windows平台,则可以使用随TortoiseSVN一起分发的SubWCRev工具。文档在这里。

#12


1  

You can use svn pre-commit-hooks to do it.
The general idea I have in mind is create one that before the commit will put the new revision number in the file (get it using svnlook) or maybe change a bogus property on the file (it has to change or SVN will ignore it).

您可以使用svn pre-commit-hooks来完成它。我想到的一般想法是创建一个在提交之前将新版本号放入文件(使用svnlook获取)或者可能更改文件上的伪属性(它必须更改或SVN将忽略它)。

For more information about pre-commit-hooks I found this page useful.

有关预提交挂钩的更多信息,我发现此页面很有用。

#13


1  

I think the best approach to ensuring that there is a file in your web application that has the SVN revision number is to not have a file you commit, but rather to extract it as part of your build script.

我认为确保Web应用程序中存在具有SVN修订号的文件的最佳方法是不提交您提交的文件,而是将其作为构建脚本的一部分提取。

If you use maven, you can do this with the maven-buildnumber-plugin.

如果您使用maven,则可以使用maven-buildnumber-plugin执行此操作。