在将提交消息发送到 git-svn 中的 SVN 之前,我可以在提交消息中添加一个字符串吗?

发布于 2024-12-12 05:04:43 字数 196 浏览 0 评论 0原文

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

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

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

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?

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

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

发布评论

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

评论(2

樱娆 2024-12-19 05:04:43

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

有关 git hook 的文档

在项目的 .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

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
纵山崖 2024-12-19 05:04:43

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

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

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文