Yuval Atzmon
Yuval Atzmon

Reputation: 5945

How does one show untracked files in current directory only while using .gitignore filter?

As a followup on this question

The answer there show all untracked files. How to show untracked files in current directory only, and use the .gitignore, i.e. files in .gitignore shouldnt be shown?

Thanks

Upvotes: 0

Views: 85

Answers (1)

Leon
Leon

Reputation: 32464

Your requirements are not quite clear.

If you want to see only untracked files that match the .gitignore filter then

git ls-files --other --exclude-standard --ignored|grep -v /

If you want to see only untracked files that do not match the .gitignore filter then

git ls-files --other --exclude-standard|grep -v /

Used options of git ls-files:

-o, --others Show other (i.e. untracked) files in the output

-i, --ignored Show only ignored files in the output. When showing files in the index, print only those matched by an exclude pattern. When showing "other" files, show only those matched by an exclude pattern.

--exclude-standard Add the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user’s global exclusion file.

Files not from the current directory are filtered out with grep.

Upvotes: 1

Related Questions