.dockerignore all subfolders but not files in the folder itself

I have a folder structure as shown below. I want to ignore all subfolders (and all their content) .git, but include all files that are directly in .git(for example, FETCH_HEAD and HEAD).

How to write this in a file .dockerignore.

.git
├── COMMIT_EDITMSG
├── FETCH_HEAD
├── HEAD
├── description
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
+4
source share
3 answers

According to the documentation, you can ignore only subdirectories:

.git/*/*

You do not need to manually exclude files that are directly in the directory .git.

+2
source

One possibility is to exclude files to ignore with !.

.git/*/
!.git/HEAD
!.git/FETCH_HEAD
+2
source

docker 1.7, a .dockerignore :

*/*
!FETCH_HEAD
!HEAD
+1

Source: https://habr.com/ru/post/1654695/


All Articles