【问题标题】:Can I add a string to my commit messages before sending them to SVN in git-svn?在将提交消息发送到 git-svn 中的 SVN 之前,我可以在提交消息中添加一个字符串吗?
【发布时间】:2011-10-28 16:31:04
【问题描述】:

我的组织有一些愚蠢的要求,您必须在每条 SVN 提交消息的末尾加上“admin”,以便绕过 SVN 看门人做出的每个提交都应该有一个关联的错误编号的决定。 (团队中的每个人都类似地绕过了这个要求。)

我正在尝试使用 git SVN,但我想避免在我频繁的 git-svn 提交的末尾加上“admin”。

有没有办法让 git SVN 为我做这件事?

【问题讨论】:

    标签: git svn git-svn


    【解决方案1】:

    你可以设置一个 git commit 钩子,这样当你提交到 git 时,它会在提交消息中附加"admin"。然后,当您执行 git svn dcommit 时,您的提交消息将已经包含预期的字符串。

    Documentation on git hooks.

    在你项目的.git目录下,会有一个名为hooks的目录。

    cwd: ~/testrepo/.git/hooks master 
    λ > ls
    applypatch-msg.sample  post-update.sample     pre-commit.sample      prepare-commit-msg.sample
    commit-msg.sample      pre-applypatch.sample  pre-rebase.sample      update.sample
    

    您可以查看文件,prepare-commit-message.sample 可用于在提交之前编辑提交消息。

    复制prepare-commit-message.sample 并将其命名为prepare-commit-message

    cp prepare-commit-message.sample prepare-commit-message
    

    所以打开那个文件,作为演示,我将这一行添加到末尾:

    # Append 'admin' to the end of the commit message, $1 is the message passed as argument
    echo "admin" >> "$1"
    

    保存更改、退出、尝试更改并提交。

    λ > echo etc >> README 
    λ > git add .
    λ > git commit -m "testing"
    [master 89a435d] testing admin
     1 files changed, 1 insertions(+), 0 deletions(-)
    
    λ > git log
    commit 89a435d5e110229d3c9989bfb464ae2420eb5088
    Author: birryree
    Date:   Fri Oct 28 12:54:20 2011 -0400
    
        testing
        admin
    

    【讨论】:

      【解决方案2】:

      几个想法,但每个都需要一点工作:

      1. 使用 git commit-msg 挂钩自动在消息末尾添加“admin”。
      2. 编写一个脚本,使用 git filter-branch --msg-filter 在执行 dcommit 之前运行的消息末尾添加“admin”。
      3. 说服 SVN 管理员删除明显无用的要求,因为每个人都绕过它。

      【讨论】:

        猜你喜欢
        • 2014-09-20
        • 1970-01-01
        • 2021-06-18
        • 2019-03-29
        • 2013-12-24
        • 2013-03-01
        • 1970-01-01
        • 2012-05-04
        • 2011-09-07
        相关资源
        最近更新 更多