Exclude files from pull request diffs

Only repository administrators can add files to be excluded from the diff view.


The pull request view shows each file modified in the pull request. You can exclude files from appearing in the diff view of a pull request by specifying patterns in the 'Excluded files' repository setting page.

To exclude certain files from appearing in pull requests:

  1. In the repository containing the pull request, click Repository settings > Excluded files in the Pull Requests section.

  2. In the Patterns field, enter patterns to exclude from pull request diff views.

  3. Click Save.

Each line you add to the Patterns field specifies a pattern to exclude. 

A pattern can be:

  • a filename (e.g. index.min.js).

  • a path relative to the repository root (e.g. /minified/index.min.js).

  • a pattern including wildcards (e.g. *.min.js or /minified/** ).

Files that match any pattern entered will still appear in the file tree and in the list of files changed for a pull request, but the changed content of those excluded files won't appear in the diff view.

Excluded files pattern format

The excluded files repository setting format is similar to the .gitignore pattern format with two notable exceptions:

  • Trailing spaces are not allowed.

  • There is no way to negate a pattern.

Important details

  • Matching is case-insensitive.

  • Directories are indicated by a forward slash "/".

  • Backslash "\" is used to escape special characters.

  • Non-ASCII characters are supported. UTF-8 encoding is assumed.

Example

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # package manager lock files (at the repository root) /Gemfile.lock /package-lock.json # minified JS and CSS (anywhere in the repository) *.min.js *.min.css # third-party libraries /vendor/** # generated XML (inside any my-code-generator/ directory) my-code-generator/*.xml # text files from November 2017 notes/2017-11-[0-3][0-9].txt

Blank lines and comments

File patterns can be organized with blank lines and comments. Each non-blank line can contain either a pattern or a comment, not both.

Pattern

Matches

Notes

[blank line]

Nothing

Blank lines can be used as separators.

# comment

Nothing

Any line beginning with # is ignored.

Filename

A file or files can be excluded by filename. If a filename contains special characters, those characters must be escaped with backslashes.

  • To exclude a single, specific file, start your pattern with "/" which returns matches relative to the root of the repository.

  • To exclude every file that matches a filename, do not add the leading "/".

Pattern

Matches

Notes

/package-lock.json

  • package-lock.json

A single file named package-lock.json at the root of the repository.

package-lock.json

  • package-lock.json

  • some/path/package-lock.json

Any file named package-lock.json anywhere in the repository.

/lib/foo.lib

  • lib/foo.lib

A single file named foo.lib in a directory named lib at the root of the repository.

lib/foo.lib

  • lib/foo.lib

  • some/other/lib/FOO.LIB

Any file named foo.lib in a directory named lib anywhere in the repository.

file\[version\ 2\].js

  • file[version 2].js

  • some/file[version 2].js

Any file named file[version 2].js. Note the backslashes in the pattern.

Directory name

A pattern ending with "/" matches files contained in that directory.

Pattern

Matches

Notes

/minified/

  • minified/file_a.min.css

  • minified/file_b.min.js

Any file in a directory named minified at the root of the repository.

minified/

  • minified/file_a.min.css

  • some/path/MINIFIED/file_b.min.js

Any file in a directory named minified anywhere in the repository.

minified/js/

  • minified/js/file_a.min.js

  • some/path/minified/js/file_b.min.js

Any file in a directory named js in a directory named minified anywhere in the repository.

Wildcards

[] wildcard

The [] wildcard matches one character in a selected range or character class.

Pattern

Matches

Notes

file_[xyz].c

  • file_x.c

  • some/path/file_y.c

  • some/other/path/file_z.c

[] can include a list of specific characters.

file_[a-z].c

  • file_a.c

  • some/path/FILE_R.c

  • some/other/path/file_z.c

[] can be used with - to specify a range of characters.

file_[0-9][0-9].c

  • file_00.c

  • some/path/file_15.c

  • some/other/path/file_99.c

[0-9] matches a single digit.

file_[]-].c

  • file_].c

  • some/path/file_-.c

[] is one way to match special characters.

Note: A right bracket "]" normally marks the end of a character class. It is included in the character class if it appears first in the list.

file_[高雄].c

  • some/path/file_高.c

Non-ASCII characters are supported.

? wildcard

The ? wildcard matches any single character except "/".

Pattern

Matches

Notes

file_?.c

  • file_x.c

  • some/path/file_y.c

  • snowman/file_☃.c

  • mountain/file_山.c

Non-ASCII characters are supported.

* wildcard

The * wildcard matches anything except "/".

Pattern

Matches

Notes

*.min.js

  • core.min.js

  • some/path/index.min.js

 

file_*.c

  • file_.c

  • file_x.c

  • some/path/file_門員.c

  • some/file_stuff [version 2].c

* can match an empty string.

dir*/file.c

  • dir/file.c

  • some/path/directoryX/file.c

 

** wildcard

The ** wildcard matches anything in the path name including nested directories. Using more than two consecutive ** results in an invalid pattern that matches nothing.

Pattern

Matches

Notes

**/*.min.js

  • core.min.js

  • some/path/index.min.js

Same as *.min.js.

my/path/**

  • my/path/leftpad.js

  • other/MY/PATH/patent/middleout.rb

A trailing /** matches everything in the last named directory.

my/path/**/*.min.js

  • my/path/core.min.js

  • other/my/path/some/index.min.js

 

/lib/**/py/

  • lib/py/data_science.py

  • lib/work_in_progress/py/secret.py

/**/ matches zero or more directories.

 

Still need help?

The Atlassian Community is here for you.