List all files that are not ignored by .gitignore

后端 未结 2 1059
情歌与酒
情歌与酒 2021-02-13 18:37

I would like to list all files that are not ignored by .gitignore, ie all source files of my repository.

ag does it well by default, but I\'m not aware of

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-13 18:53

    Here is another way, using git check-ignore which you may find it cleaner:

    find . -type f
    

    will give you all the files in the current folder.

    find . -type f -not -path './.git/*'
    

    will give you all the files, with the exception of everything in .git folder, which you definitely don't want to include. then,

    for f in $(find . -type f -not -path './.git/*'); do echo $f; done
    

    is the same as above. Just a preparation to the next step, which introduce the condition. The idea is to use the git check-ignore -q which returns exit 0 when a path is ignored. Hence, here is the full command

    for f in $(find . -type f -a -not -path './.git/*'); do
        if ! $(git check-ignore -q $f); then echo $f; fi
    done
    

提交回复
热议问题