LoginSignup
0
0

More than 3 years have passed since last update.

git commitで使う引数を渡す方法[aliasで時短]

Last updated at Posted at 2019-11-02

git commit -m "mod method" filename1 filename2 filename3
と長くなる問題、なんとかしたので、共有します。

ファイルをgit addからpushするまでのコマンドとしてはこんなかんじになります。

gkz@localhost~/workspace/demo (master) $ ga README.md 
gkz@localhost~/workspace/demo (master) $ gc "first" README.md 
gkz@localhost~/workspace/demo (master) $ gpu master

上のコマンドは~/.bashrcに記載したaliasを使っています。

$ tail  ~/.bashrc
alias ga="~/.sh/gitadd.sh"
alias gc="~/.sh/gitcommit.sh"
alias gpu="~/.sh/gitpush.sh"

~/.bashrcに記載したshellで引数を取得しています。

$ cat ~/.sh/gitadd.sh 
#!/bin/bash

git add $@
$ cat ~/.sh/gitcommit.sh 
#!/bin/bash

#${@:2}: 一番最初以外の引数
git commit -m "$1" ${@:2}
$ cat ~/.sh/gitpush.sh 
#!/bin/bash

git push origin $@

みなさんのgit tips、コメントにて共有いただけると嬉しいです。

P.S. Twitterもやってるのでフォローしていただけると泣いて喜びます!
@gkzvoice

0
0
2

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