Make .gitignore ignore everything except a few files

前端 未结 23 2943
无人共我
无人共我 2020-11-22 00:14

I understand that a .gitignore file cloaks specified files from Git\'s version control. I have a project (LaTeX) that generates lots of extra files (.auth, .dvi, .pdf, logs,

23条回答
  •  眼角桃花
    2020-11-22 01:01

    If you want to ignore the whole content of a directory except one file inside it, you could write a pair of rules for each directory in the file path. E.g. .gitignore to ignore the pippo folder except from pippo/pluto/paperino.xml

    pippo/*
    !pippo/pluto
    pippo/pluto/*
    !pippo/pluto/paperino.xml
    

    Note that if you simply had written above:

    pippo/*
    !pippo/pluto/paperino.xml
    

    It wouldn't work because the intermediary pluto folder would not exist to Git, so paperino.xml could not find a place in which to exist.

提交回复
热议问题