Though these ignore files have similar sytnax, e.g. line oriented;
# leading comment line; wildcard via glob pattern; etc. The semantic meanings are not necessarily the same.
In .gitignore, a relative path (e.g.
filename) matches the path under any directory;
while in .dockerignore, a relative path (e.g.
filename) is the same as a rooted one (e.g.
/filename) and matches only ones under the root. To match the path under any directory,
**/filename should be used.
Files Under Ignored Path
In .gitignore, if a path is listed as ignored (e.g.
/dir), then any files or folders under that path is ignored and it is not possible to re-include them via negation (e.g.
!/dir/file) as the parent directory of them is excluded;
while in .dockerignore, even if a parent path is ignored, files or folders under it can still be re-included via negation.