Make .gitignore ignore everything except a few files

前端 未结 23 2614
无人共我
无人共我 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 00:56

    I also had some issues with the negation of single files. I was able to commit them, but my IDE (IntelliJ) always complained about ignored files, which are tracked.

    git ls-files -i --exclude-from .gitignore
    

    Displayed the two files, which I've excluded this way:

    public/
    !public/typo3conf/LocalConfiguration.php
    !public/typo3conf/PackageStates.php
    

    In the end, this worked for me:

    public/*
    !public/typo3conf/
    public/typo3conf/*
    !public/typo3conf/LocalConfiguration.php
    !public/typo3conf/PackageStates.php
    

    The key was the negation of the folder typo3conf/ first.

    Also, it seems that the order of the statements doesn't matter. Instead, you need to explicitly negate all subfolders, before you can negate single files in it.

    The folder !public/typo3conf/ and the folder contents public/typo3conf/* are two different things for .gitignore.

    Great thread! This issue bothered me for a while ;)

提交回复
热议问题