LoginSignup
23
28

More than 5 years have passed since last update.

Gitでcommitした時にブランチ名をcommitメッセージに自動でいれる

Posted at

.git/hookディレクトリ以下にgitでcommitをした時などに呼ばれるスクリプトがあります。

今回はcommitメッセージを変更するhookファイルにスクリプトを書きます。

$ vi .git/hook/prepare-commit-msg
#!/usr/bin/env ruby

#今いるブランチ名を取得
current_branch = `git branch | grep '*'`.chomp.sub('* ', '')

commit_msgs = File.readlines(ARGV[0])
open(ARGV[0], 'w') {|file|
    file.print "#{current_branch}:"
    file.puts commit_msgs
}

これで自動で
<ブランチ名>:<コミットメッセージ>

となります。

23
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
28