同步你的subversion repository Gentoo里gnome下修改qt程序的外观
Mar 16

  在cvs中这个比较好做。只要在文件中有这样的字条串
  @version $Id: ForumAtta.java Exp $
cvs就会将$Id....$这段内容换成该文件的最后提交日期和提交人的信息
  @version $Id: ForumAtta.java,v 1.1 2006/11/09 13:58:50 rory Exp $
但是在subversion中仅仅这样就不行了,那我们该怎样做呢。
首先我们可以使用subclipse来手工添加这些属性
subversion_set_by_hand
在下拉框中选择 svn:keywords 值就填上 Id Reversion Date
show_props
这种方法虽然可用,但是用起来不太现实,我们需要给某些文件自动的添加这些属性。那我们就要修改本地的subversion配置了
gentoo rory # cd ~/.subversion
gentoo .subversion # vi config

找到文件的最后一段
[auto-props]
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
# *.h = svn:eol-style=native
# *.dsp = svn:eol-style=CRLF
# *.dsw = svn:eol-style=CRLF
# *.sh = svn:eol-style=native;svn:executable
# *.txt = svn:eol-style=native
# *.png = svn:mime-type=image/png
# *.jpg = svn:mime-type=image/jpeg
# Makefile = svn:eol-style=native

我们为需要自动设置属性的文件添加配置
[auto-props]
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
# *.h = svn:eol-style=native
# *.dsp = svn:eol-style=CRLF
# *.dsw = svn:eol-style=CRLF
# *.sh = svn:eol-style=native;svn:executable
# *.txt = svn:eol-style=native
# *.png = svn:mime-type=image/png
# *.jpg = svn:mime-type=image/jpeg
# Makefile = svn:eol-style=native
*.java = svn:keywords=Id Revision Date
*.xml = svn:keywords=Id Revision Date

最后还有重要的一点是启用auto-props

[miscellany]
enable-auto-props = yes

这样的话以后我们添加的java和xml文件只要文件里有 $Id$,$Revision$,$Date$ 这些字符都会自动替换成最后提交的相关属性.
before_auto_props
after_auto_props


Like others

15 Responses to “如何让subversion自动添加Id,Revision等keywords”

  1. 莫多(somebody) Says:

    忘了说windows下的配置文件路径了。
    应该是在
    C:\Documents and Settings\YouUsername\Application Data\Subversion
    目录下。

  2. tianyue Says:

    呵呵 ,一直都再关注你的blog,猜猜我是谁,进www.bashu.info看看 吧。

  3. 莫多(somebody) Says:

    谢谢关注。强。用E文写。
    刚刚搭起来的吧。不过我还是没有猜出来你是谁。

  4. donoiz Says:

    谢谢!知道怎么用了。

  5. 莫多(somebody) Says:

    不客气。

  6. Ethan Tsien Says:

    是Revision不是Reversion,作者修改配置文件的那里写错了

  7. 莫多(somebody) Says:

    感谢 Ethan Tsien 提出来。这就修改过来。

  8. Ethan Tsien Says:

    "这样的话以后我们添加的java和xml文件只要文件里有 $Id$,$Reversion$,$Date$ 这些字符都会自动替换成最后提交的相关属性."

    是这里的$Reversion$,还是没改嘛

  9. 莫多(somebody) Says:

    再次感谢。 @Ethan Tsien

    看来我应该用查找替换法。

  10. jaclon Says:

    很实用的东西,讲的很详细

  11. 三桂 Says:

    $Id$ 显示的时间(时分秒)貌似有问题(不正确+格式不本地化,如:2011-08-29 06:45:16Z),如何解决?
    $Date$貌似可以,但是$Id$更符合我的要求...

  12. 三桂 Says:

    楼主,如果有解决方案,麻烦发我邮件,谢谢:D

  13. 莫多(somebody) Says:

    这个时间有问题?这个是 UTC时间呀。你加个8小时就是locale time了呀。

    如果你觉得 $Date$可以。那就两个一起用了?

    @Version $Id$
    @Date $Date$

    这样?

  14. 三桂 Says:

    这个时间是不能格式化的么?跟本地时间不统一看起来有点别扭...在哪里可以设置?

  15. 莫多(somebody) Says:

    看起来是不可以的。
    要用local time 只能用 $Date$

    http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html

Leave a Reply

Identifying Code