昨日、作業ブランチにpushする時の入力は面倒だけど、pushするブランチは確認したいを書きましたが、
よくよく考えてみたらコミットの段階で確認出来た方が良い事に気が付いたので、そのシェルスクリプトを作ってみました。
作ったもの
- commit時に現在ブランチ、入力したコメントが出力される
-
y
orY
の入力でコミットされる - 修正されたファイルの一覧が見れる
addしないままコミットしてしまうこともあったので、修正ファイルも表示されるようにしました。
~/.bashrc
gitcommit(){
branch=`git rev-parse --abbrev-ref HEAD`
if [ -z $branch ]; then
return
fi
git status
comment=$1
if [ -z $comment ]; then
echo '>> Comment is Required.'
return
fi
echo "[branch] $branch"
echo "[comment] $comment"
read input
if [ -z $input ]; then
return
fi
if [ $input = 'y' ] || [ $input = 'Y' ]; then
git commit -m $comment
else
return
fi
}
gitcommt <COMMENT>
で実行します。
Ariel:bash gatapon$ gitcommit
On branch gt.test
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: first.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: test2.txt
>> Comment is Required.
コメントがなければ終了する。
Ariel:bash gatapon$ gitcommit コミットしてみる
On branch gt.test
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: first.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: test2.txt
[branch] gt.test
[comment] コミットしてみる
現在のワークスペースとステージの状況が表示され、現在のブランチとコメントが確認できる。
y
or Y
を入力すると実行
[branch] gt.test
[comment] コミットしてみる
y
[gt.test 6d163de] コミットしてみる
1 file changed, 1 insertion(+)