13

git commitテキスト エディターが開き、コミットする変更に関する情報が表示されます。

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#

#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#

このテンプレートを拡張して表示したい

  • N最後のコミット メッセージの最初の行および/または
  • 最後のコミットの完全なメッセージ

現在のブランチの。どうやってやるの?

4

1 に答える 1

14

これは git を使用しますhooks

  • プロジェクトのルート ディレクトリで、次の場所に移動します。.git/hooks/
  • 今すぐファイルを作成しますprepare-commit-msg
  • 次のコードを追加します。
#!/bin/sh
ORIG_MSG_FILE="$1"  # Grab the current template
TEMP=`mktemp /tmp/git-msg-XXXXX` # Create a temp file
trap "rm -f $TEMP" exit # Remove temp file on exit

MSG=`git log -1 --pretty=%s` # Grab the first line of the last commit message

(printf "\n\n# Last Commit: %s \n\n" "$MSG"; cat "$ORIG_MSG_FILE") > "$TEMP"  # print all to temp file
cat "$TEMP" > "$ORIG_MSG_FILE" # Move temp file to commit message
  • chmod +x prepare-commit_message

Enhancing git commit messagesから借用したアイデア

%bとを使用してコミット メッセージ全体を取得%Bできますが、複数行のコミットで問題が発生する可能性があります。%-bとに夢中になるか、ドキュメンテーション%-Bでもっと読むことができるかもしれません(スクロールしてフォーマットします)

于 2013-09-28T06:41:56.453 に答える