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 an approach that works without installing additional software.
git ls-files
without options works almost well but doesn't take into account the files that have been modified/created, for example if I create a new file bar without commiting it, git ls-files
doesn't show that file.
gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.
6 onwards you can also use git status --ignored in order to see ignored files.
git status --short| grep '^?' | cut -d\ -f2-
will give you untracked files.
If you union it with git ls-files
, you've got all unignored files:
( git status --short| grep '^?' | cut -d\ -f2- && git ls-files ) | sort -u
you can then filter by
( xargs -d '\n' -- stat -c%n 2>/dev/null ||: )
to get only the files that are stat-able (== on disk).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With