物理削除されたファイルをまとめて awk で git rm する

More than 1 year has passed since last update.

きわめて個人的なメモ。ちなみにAWKを使っているのに必然性はありません。sedでもperlでも。

#確認
 git status -s | awk '/^ D/{print "git rm "$2}' 

#実行
 git status -s | awk '/^ D/{print "git rm "$2}' | sh

別にファイルリストの取得は git ls-files --deleted などでも。

もちろん、全変更を突っ込みたければ git add -u とか git add -A などでもいいと思います。

実行例

$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    hello/1
#   deleted:    hello/2
#   deleted:    hello/3
#   deleted:    hello/4
#   deleted:    hello/5
#   deleted:    hello/6
#   deleted:    hello/7
#   deleted:    hello/8
#   deleted:    hello/9
#   deleted:    hello/FizzBuzz
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git status -s | awk '/^ D/{print "git rm "$2}'
git rm hello/1
git rm hello/2
git rm hello/3
git rm hello/4
git rm hello/5
git rm hello/6
git rm hello/7
git rm hello/8
git rm hello/9
git rm hello/FizzBuzz

$ git status -s | awk '/^ D/{print "git rm "$2}' | sh
rm 'hello/1'
rm 'hello/2'
rm 'hello/3'
rm 'hello/4'
rm 'hello/5'
rm 'hello/6'
rm 'hello/7'
rm 'hello/8'
rm 'hello/9'
rm 'hello/FizzBuzz'

$ git status -s
D  hello/1
D  hello/2
D  hello/3
D  hello/4
D  hello/5
D  hello/6
D  hello/7
D  hello/8
D  hello/9
D  hello/FizzBuzz
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.