Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
20
Help us understand the problem. What is going on with this article?
@yatemmma

gitのaliasコマンドに引数を渡す方法

More than 5 years have passed since last update.

gitのaliasコマンドに引数を渡す

引数の渡し方をいろいろ調べたのでメモ。
関数を使うやり方の方が分かりやすくて良さそう。

[alias]
        command1 = "!sh -c 'echo $1 $2' -"
        command2 = "!f(){ echo $1 $2;};f"
$ git command2 hoge fuga
hoge fuga

sh -c を使う

command1 = "!sh -c 'echo $1 $2' -"

最後のハイフンは$0を消すためのダミー。
ハイフン無しで'echo $0 $1'とすると、引数ありの時は一つ目が\$0に。無しの時は\$0にshが入る。

関数を使う

command2 = "!f(){ echo $1 $2;};f"

こちらは見ての通り。{の後のスペースを詰めると動かないので注意。

20
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
yatemmma
鳥取にいます
lassic
ITを駆使して地方を元気にする株式会社LASSIC(ラシック)。地方を舞台に自分らしく働く優秀な技術者が、貴社のWEB・スマートフォンサイトやアプリ開発、システム開発プロジェクトを成功へと導きます。~鳥取発~ITで地方創生

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
20
Help us understand the problem. What is going on with this article?