0

I would like to get the all existing files ignored by git repository or in my local also if it is possible and explaining the command

I have tried this commands but not working.


git ls-files --ignored -o

result is

fatal: ls-files --ignored needs some exclude pattern


and this one also

git ls-files --others --exclude=*.o --ignored

result is

zsh: no matches found: --exclude=*.o


and this also

git check-ignore -v 

result is

fatal: no path specified


Please explain what is the benefit of this and why I couldn't find the right answer and how to search in docs of gits for the right command because I couldn't manage it.

I tried the solution mentioned in this link and the result i got is this

git ls-files --ignored -X /path/to/gitignore
fatal: cannot use /path/to/gitignore as an exclude file

Learning the Linux and git tool and improving my skills in that area

4
  • stackoverflow.com/search?q=%5Bgit%5D+show+ignored+files Commented Jul 8 at 21:58
  • git status --ignored , git check-ignore **/* , git ls-files --ignored --others --exclude-standard Commented Jul 8 at 22:00
  • The error message "zsh: no matches found: --exclude=*.o" suggests to quote the asterisk or escape it with backslash; either git ls-files --ignored --others --exclude="*.o" or git ls-files --ignored --others --exclude=\*.o Commented Jul 8 at 22:01
  • On the error "fatal: cannot use /path/to/gitignore as an exclude file" — do you understand that path/to/gitignore is just a placeholder where you should put in your absolute or relative path? Most probably just .gitignore or ./.gitignore could be enough. Commented Jul 8 at 22:52

1 Answer 1

1

In git, there is a .gitignore file where you can write patterns with wildcards or paths to exclude of being tracked by git.

Moreover, you can use the following command to list all the excluded files.

git ls-files --others --ignored --exclude-standard

  • --others: Lists non-tracked files.

  • --ignored: Includes matching .gitignore files.

  • --exclude-standard: Applies .gitignore rules, .git/info/exclude and $GIT_DIR/info/exclude if different.

  • You have to add -d option to the command if you need to list also directories.

There is also an option of git status command, where you can sum up this interactively.

You can also check git documentation: https://git-scm.com/docs/git-ls-files

I hope that helps.

Sign up to request clarification or add additional context in comments.

4 Comments

Are you sure you can use regular expressions in .gitignore? I think only wildcards are supported, not regular expressions.
You are right. It only supports wildcards.
it is correct command but can you provide me and example if you have time like where i will use that command exactly in my projects
Of course. You should run this command from your bash or an integrated command line in the IDE you are using to write your code. You should be placed inside the directory that contains the .git folder (not inside de .git). From that directory and every directory inside of it, you should be able to run git commands. However, the logical thing would be to run it from the root directory, that is the one containing the git directory. The output of the command above will be the ignored files. I hope that helps.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.