簡體   English   中英

在將它們發送到git-svn中的SVN之前,是否可以在我的提交消息中添加字符串?

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

我的組織有一些愚蠢的要求,你必須在每個SVN提交消息的末尾放置“admin”,以便繞過SVN網守的一些決定,即每個提交應該有一個相關的錯誤號。 (團隊中的每個人都同樣繞過了這個要求。)

我正在嘗試使用git SVN,但我想避免在我頻繁的git-svn提交結束時輸入“admin”。

有沒有辦法讓git SVN為我做這個?

一些想法,但每個都需要一些工作:

  1. 使用git commit-msg鈎子自動在消息末尾添加“admin”。
  2. 編寫一個腳本,使用git filter-branch --msg-filter將“admin”添加到您在執行dcommit之前運行的消息的末尾。
  3. 說服SVN管理員刪除明顯無用的要求,因為每個人繞過它。

你可以設置一個git commit hook,這樣當你提交git時,它會在提交消息中附加"admin" 然后當你執行你的git svn dcommit ,你的提交消息已經有了預期的字符串。

關於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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM