LoginSignup
0
0

More than 3 years have passed since last update.

コミットする時に現在のブランチと変更ファイルの状態を確認できるスクリプト

Posted at

昨日、作業ブランチにpushする時の入力は面倒だけど、pushするブランチは確認したいを書きましたが、
よくよく考えてみたらコミットの段階で確認出来た方が良い事に気が付いたので、そのシェルスクリプトを作ってみました。

作ったもの

  • commit時に現在ブランチ、入力したコメントが出力される
  • y or Yの入力でコミットされる
  • 修正されたファイルの一覧が見れる

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(+)
0
0
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
0
0