入力が面倒
この状態で
$ git status
# On branch master
# Changes not staged for commit:
#
# modified: sub/testABC.txt
# modified: sub/testDEF.txt
# modified: testABC.txt
# modified: testDEF.txt
#
ABC
を含む2ファイルのみ追加したい。
- sub/testABC.txt
- testABC.txt
git add *ABC*
とした場合はカレントディレクトリのみが対象となる。
→ sub/testABC.txt
は追加されない (場合によっては便利)
$ git add *ABC*
$ git status
# On branch master
# Changes to be committed:
#
# modified: testABC.txt
#
# Changes not staged for commit:
#
# modified: sub/testABC.txt
# modified: sub/testDEF.txt
# modified: testDEF.txt
#
正解はgit add "*ABC*"
なのだが
- そもそも
*
で囲むのがめんどくさい -
"
や'
で囲むのもめんどくさい
aliasで解決
以下のようにaliasを追加する。
[alias]
ad = "!f() { git add \"*${1}*\" ${@:2};};f"
ファイルパスにABC
を含むファイルをさっと追加できるようになる。
$ git ad ABC
$ git st
# On branch master
# Changes to be committed:
#
# modified: sub/testABC.txt
# modified: testABC.txt
#
# Changes not staged for commit:
#
# modified: sub/testDEF.txt
# modified: testDEF.txt
#
後ろならオプション指定も使える。
$ git ad ABC -p
ついでにresetにも
[alias]
re = "!f() { git reset HEAD \"*${1}*\" ${@:2};};f"
git re ABC
でステージングされたファイルをさっと戻すのに使用している。