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

后端 未结 9 1070
我在风中等你
我在风中等你 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:01

    It should be sufficient to use

    git ls-files --others -i --exclude-standard
    

    as that covers everything covered by

    git ls-files --others -i --exclude-from=.git/info/exclude
    

    therefore the latter is redundant.


    You can make this easier by adding an alias to your ~/.gitconfig file:

    git config --global alias.ignored "ls-files --others -i --exclude-standard"
    

    Now you can just type git ignored to see the list. Much easier to remember, and faster to type.

    If you prefer the more succinct display of Jason Geng's solution, you can add an alias for that like this:

    git config --global alias.ignored "status --ignored -s"
    

    However the more verbose output is more useful for troubleshooting problems with your .gitignore files, as it lists every single cotton-pickin' file that is ignored. You would normally pipe the results through grep to see if a file you expect to be ignored is in there, or if a file you don't want to be ignore is in there.

    git ignored | grep some-file-that-isnt-being-ignored-properly
    

    Then, when you just want to see a short display, it's easy enough to remember and type

    git status --ignored
    

    (The -s can normally be left off.)

提交回复
热议问题