LoginSignup
5
5

More than 5 years have passed since last update.

.gitignoreに書いてあるけれどもインデックスされているファイルの一覧を取得する

Last updated at Posted at 2014-04-17

.gitignoreの中身を見直そうと思い、スクリプトを書いた。
(.gitignoreの行数 × git ls-filesの行数) 回のgrepをするので結構時間がかかるけれども、目的は果たせたので可とする。

git-ls-force-indexed.sh
#!/bin/sh

GITIGNOREPATH=`git rev-parse --show-toplevel`'/.gitignore'

if [ $? -ne 0 ]
then
    exit $?
fi

if [ ! -f $GITIGNOREPATH ]
then
    echo $GITIGNOREPATH' does not exist.'
    exit 1
fi

for indexed in `git ls-files`
do
    for ignored in `cat ${GITIGNOREPATH} | grep -v '^#'`
    do
        if [ `echo /${indexed} | grep -F ${ignored}` ]
        then
            echo $indexed
        fi
    done
done
5
5
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
5
5