Git command to show which specific files are ignored by .gitignore

后端 未结 9 1279
我在风中等你
我在风中等你 2020-11-22 05:07

I am getting my feet wet with Git and have the following issue:

My project source tree:

/
|
+--src/
+----refs/
+----...
|
+--vendor/
+----...
         


        
9条回答
  •  甜味超标
    2020-11-22 06:05

    While generally correct your solution does not work in all circumstances. Assume a repo dir like this:

    # ls **/*                                                                                                       
    doc/index.html  README.txt  tmp/dir0/file0  tmp/file1  tmp/file2
    
    doc:
    index.html
    
    tmp:
    dir0  file1  file2
    
    tmp/dir0:
    file0
    

    and a .gitignore like this:

    # cat .gitignore
    doc
    tmp/*
    

    This ignores the doc directory and all files below tmp. Git works as expected, but the given command for listing the ignored files does not. Lets have a look at what git has to say:

    # git ls-files --others --ignored --exclude-standard                                                            
    tmp/file1
    tmp/file2
    

    Notice that doc is missing from the listing. You can get it with:

    # git ls-files --others --ignored --exclude-standard --directory                                                
    doc/
    

    Notice the additional --directory option.

    From my knowledge there is no one command to list all ignored files at once. But I don't know why tmp/dir0 does not show up at all.

提交回复
热议问题