Are multiple `.gitignore`s frowned on?

后端 未结 5 1708
遥遥无期
遥遥无期 2020-12-04 06:48

Unless a repo consisted of several independent projects, it seems it would be simplest to just have one .gitignore file at the root of the repo than various one

5条回答
  •  一向
    一向 (楼主)
    2020-12-04 07:22

    There are many scenarios where you want to commit a directory to your Git repo but without the files in it, for example the logs, cache, uploads directories etc.

    So what I always do is to add a .gitignore file in those directories with the following content:

    *
    !.gitignore
    

    With this .gitignore file, Git will not track any files in those directories yet still allow me to add the .gitignore file and hence the directory itself to the repo.

提交回复
热议问题