1. The ignore file and the paths
Load an example or type your own. Everything is evaluated in this page; nothing is sent anywhere.
2. Path by path
3. The rules each column applies
git (gitignore(5), PATTERN FORMAT)
- G1
- A blank line matches nothing. A line starting with # is a comment; a backslash before the first # makes it a literal.
- G2
- Trailing spaces are ignored unless quoted with a backslash.
- G3
- A leading ! re-includes a file excluded by an earlier pattern. gitignore(5): "It is not possible to re-include a file if a parent directory of that file is excluded."
- G4
- gitignore(5): "If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level."
- G5
- gitignore(5): "If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories."
- G6
- * and ? never match a slash; [a-z] ranges follow fnmatch with FNM_PATHNAME. gitignore(5): "a backslash at the end of a pattern is an invalid pattern that never matches."
- G7
- A leading **/, a trailing /** and a /**/ in the middle span directories. Any other run of asterisks acts as an ordinary asterisk.
Deciding line: gitignore(5) says "within one level of precedence, the last matching pattern decides the outcome". When a parent directory is excluded, the line that excluded the parent decides, and a later ! line for the child is shown struck through as having no effect.
Docker (docs plus moby/patternmatcher and tonistiigi/fsutil source)
- D1
- Reading the file: a UTF-8 byte order mark on line 1 is stripped, a line starting with # is a comment, whitespace is trimmed, each pattern is cleaned and one leading slash is removed. Docker docs: "Leading and trailing slashes in ignore patterns are disregarded." and "For historical reasons, the pattern . is ignored."
- D2
- Docker docs: "Matching is done using Go's filepath.Match function rules." The patternmatcher source compiles each pattern to its own regular expression anchored at both ends, so every pattern is anchored at the context root; ** matches any number of directories.
- D3
- A pattern matches a path when it matches the path or one of its parent directories. Docker docs: "the last line of the .dockerignore that matches a particular file determines whether it's included or excluded."
- D4
- A ! line is tested against the file itself, so a ! line naming a path inside an excluded directory re-includes it in Docker. fsutil skips walking an excluded directory only when no exception line could match inside it.
- D5
- No implicit **/ in front: target excludes target and target/x, not src/target/x. Docker docs, on *.md then !README.md: "Note that markdown files under subdirectories are still included."
- D6
- The trailing slash is removed when the pattern is cleaned, so foo/ also excludes a file named foo.
- D7
- Docker docs: "A Dockerfile-specific ignore-file takes precedence over the .dockerignore file at the root of the build context if both exist." The specific file sits next to the Dockerfile and is named after it.
- D8
- An excluded Dockerfile or .dockerignore is still sent. Docker docs: "These files are still sent to the builder as they're needed for running the build. But you can't copy the files into the image using ADD , COPY , or bind mounts."
4. Self test
Every case runs through the same two evaluators as section 2. Expected answers come from the cited rule text; the eleven row worked example was also run through git check-ignore and through a real Docker build (see the README). The last row is a positive control: an assertion written to be wrong. If it ever reports that it held, the suite is not really running.
5. What this page models, and what it does not
- git column: ONE .gitignore at the root. Nested .gitignore files, info/exclude and core.excludesFile are not modelled, and neither is core.ignorecase (matching here is case sensitive). gitignore(5) also says "Files already tracked by Git are not affected", so a tracked file stays tracked whatever this page says. For the git side alone, git check-ignore -v gives the same answer and is the command to use.
- Docker column: the client side walk of a local build context on Linux or macOS, where a backslash escapes the next character. On a Windows client patternmatcher treats a backslash as a path separator; that is not modelled.
- Not modelled: symbolic links, file permissions, case insensitive file systems, and Docker pattern escapes other than \d \D \w \W \s \S \b \B \f \n \r \t \v. Those listed are read the way Go's regular expression engine reads them (\d as a digit class, for example) and flagged when they appear.
- patternmatcher's escape table only covers characters below code 64, so |, { and } in a wildcard line reach Go's regular expression engine unescaped: the line [ab]| matches every path. The Docker column follows that reading and flags the line.
- A helper that rewrites a .gitignore into an equivalent .dockerignore is out of scope: equivalence cannot be proved from this page.
This is an independent tool. It is not affiliated with or endorsed by Docker, Inc. or the Git project.