LoginSignup
22
21

More than 5 years have passed since last update.

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

Last updated at Posted at 2013-08-08

きわめて個人的なメモ。ちなみに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
22
21
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
22
21