Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all files that are not ignored by .gitignore

Tags:

git

file

list

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.

like image 487
edi9999 Avatar asked Aug 21 '16 13:08

edi9999


People also ask

Why are files in Gitignore not ignored?

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.

Does git show ignored files?

6 onwards you can also use git status --ignored in order to see ignored files.


1 Answers

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).

like image 67
PSkocik Avatar answered Sep 19 '22 13:09

PSkocik