1

I have this structure:

versions
├── library-3.1
│   ├── Dockerfile
│   ├── options
│   └── armhf
│       ├── Dockerfile
│       └── rootfs.tar.xz
├── library-3.6
│   ├── Dockerfile
│   ├── options
│   └── x86_64
│       ├── Dockerfile
│       └── rootfs.tar.xz
...

I want git to ignore any folder under versions/**/ (like versions/**/armhf and versions/**/x86_64), but keep tracking the files options and Dockerfile

Any ideas? Thanks!

3 Answers3

1
# Ignore everything under 'versions/'...
versions/*

# ...except 'options' and 'Dockerfile'
!versions/**/options
!versions/**/Dockerfile

Add any additional files you need to the excluded list.

Alternatively, add a .gitignore file to each subdirectory that you want to ignore files in. This may provide better flexibility as the project grows.

mr_carrera
  • 76
  • 6
0

Try this:

!versions/**/Dockerfile
!version/**/options
Abe
  • 1,357
  • 13
  • 31
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Rosário Pereira Fernandes Sep 19 '17 at 03:23
0

Remember:

It is not possible to re-include a file if a parent directory of that file is excluded.

Ignore files:

 versions/**

But not folders:

 !versions/**/

Then you can exclude some files (because their parent folder are not ignored)

 !versions/**/Dockerfile
 !versions/**/option

Remember:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250