I’m excluding several paths from subdirectories in git, but sometimes I want certain files to be included.
the project tree is
.
├── D
│ └── DukeNukem
│ └── drive_c
├── W
│ ├── WingCommander1rev1-1990
│ │ └── drive_c
│ ├── WingCommander2-1991
│ │ └── drive_c
│ ├── WingCommanderAcademy-1993
│ │ └── drive_c
│ └── WingCommanderArmada-1993
│ └── drive_c
...
I want the contents of all drive_[a-z]
directories to be ignored. Unless there are specific files that should be included.
For this I have the base gitignore:
# project root /.gitignore
!**/drive_c/
**/drive_c/*
(using drive_?/
, but keeping simpler here. i fails with both patterns.)
Now if I want to include /W/WingCommanderArmada-1993/drive_c/WC2.CFG
i tried
- adding gitignore to the directory with
!drive_c/WC2.CFG
- adding exception to main gitignore with
!/W/WingCommanderArmada-1993/drive_c/WC2.CFG
- using
drive_c/*
as the question bellow suggests doesn’t block the dirs, i had to use**/drive_c/*
maybe this is the problem?
I believe the answer is in .gitignore exclude folder but include specific subfolder but I cannot construct a solution using the information there.
the repo is public
A workaround that is almost working is to set fixed levels.
# main .gitignore
!/*/*/drive_c/
/*/*/drive_c/*
but even then i can’t add files back from .gitignores
in the leaf dirs, such as bellow. both lines fail. But adding the full path one to the root gitignore works.
# /W/WingCommanderArmada-1993/.gitignore
!/W/WingCommanderArmada-1993/drive_c/WC2.CFG
!./drive_c/WC2.CFG