.gitignore everything but .c and .h recursively

前端 未结 2 1229

I would like to ignore everything in a certain folder and its subfolders, except for .c and .h files.

Yet locally, i need other files too. Do i

2条回答
  •  离开以前
    2021-01-29 02:53

    The problem is that the pattern

    *
    

    excludes all directories, too. According to the gitignore documentation,

    It is not possible to re-include a file if a parent directory of that file is excluded.

    To make this work, then, you'll need to use make sure that directories are not ignored. The gitignore pattern format does not provide a way to distinguish between directories and regular files, so you'll need to do that manually. One possibility would be to put a .gitignore file in each that directory that reincludes all its subdirectories, but it would be easier to just reinclude all directories. These can be matched (exclusively) with a pattern that ends with a '/':

    !source/**/
    

    Also, you are right when you say

    But i think this also relates to the point in time, where i have to add the files, that should be ignored

    in the sense that gitignore does not apply to files that are already tracked.

提交回复
热议问题