Can I add a string to my commit messages before sending them to SVN in git-svn?

烈酒焚心 提交于 2019-12-13 00:13:51

问题


My org has some silly requirements that you must put "admin" at the end of every SVN commit message in order to get around some decision made by the SVN gatekeepers that every commit should have an associated bug number. (Everyone on the team bypasses this requirement similarly.)

I'm trying to use git SVN, but I'd like to avoid putting "admin" at the end of my frequent git-svn commits.

Is there a way to have git SVN do this for me?


回答1:


You can set up a git commit hook, so that when you commit to git, it will append "admin" to the commit message. Then when you do your git svn dcommit, your commit messages will already have the expected string there.

Documentation on git hooks.

In your project's .git directory, there will be a directory called 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

You can take a look at the files, prepare-commit-message.sample can be used to edit commit messages before they are committed.

Make a copy of prepare-commit-message.sample and call it prepare-commit-message.

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

So open that file, and as a demonstration I added this line to the end:

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

Save changes, exit, try a change, and commit it.

λ > 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:


A couple ideas, but each require a little work:

  1. Add "admin" at the end of your message automatically with the git commit-msg hook.
  2. Write a script that uses git filter-branch --msg-filter to add "admin" to the end of your messages that you run before doing a dcommit.
  3. Convince the SVN admin to remove the obviously useless requirement, given that everyone bypasses it.


来源:https://stackoverflow.com/questions/7932092/can-i-add-a-string-to-my-commit-messages-before-sending-them-to-svn-in-git-svn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!