.gitignore everything but .c and .h recursively

前端 未结 2 1231

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:35

    Ignoring * means ignore everything including top-level directories. After that git doesn't even look into subdirectories. To fix that unignore directories. Your entire .gitignore should look like this:

    # Ignore all
    *
    
    # Unignore directories
    !*/
    
    # Unignore source code files
    !source/**/*.c
    !source/**/*.h
    

    Another approach is to ignore everything but force-add necessary files with git add -f.

提交回复
热议问题