Filtering files

Learn include and exclude step by step, choose glob patterns, and resolve ignore or blacklist exclusions.

Decide what belongs in a bundle

Use filters when a project contains more than the recipient needs. In this walkthrough you will include Rust files, remove legacy code, then investigate an ignored note. Include defines the allowed set; exclude removes paths from that set. Neither one overrides ignore rules or the built-in blacklist.

In a new folder named demo, create the following files with a text editor. The text after each filename is its content; use a line break for each ↵. Use sample values only. Open a terminal in demo. Do not reuse a folder containing an existing .onesourcerc.

  • README.md: # Demo
  • src/main.rs: fn main() {}
  • src/util.rs: pub fn value() -> u8 { 1 }
  • src/legacy/old.rs: fn old() {}
  • tests/smoke.rs: #[test] ↵ fn smoke() {}
  • .gitignore: notes.txt
  • notes.txt: Local notes
  • .env: EXAMPLE_KEY=demo-only

OneSource must already be available as onesource. If it is not, follow Installation. All commands on this page start in this folder unless a step explicitly says otherwise.

1. Include the files you need

Start with the extension. -i is short for --include; quote the pattern so your shell does not expand it before OneSource receives it.

Command
onesource --no-config -i "*.rs" --dry-run

The four expected content paths are src/main.rs, src/util.rs, src/legacy/old.rs and tests/smoke.rs. README.md is outside the allowed set. If your goal is application source only, narrow by directory instead:

Command
onesource --no-config -i "src/**" --dry-run

Now expect the three files under src, with no tests/smoke.rs. To add the README as well, join patterns with a comma; matching either pattern is enough:

Command
onesource --no-config -i "src/**,README.md" --dry-run

Expect the three source files plus README.md. A comma list is a union, not a sequence of filters.

2. Remove an unwanted subset

Keep the include from the previous step and add -x (short for --exclude). A trailing slash means the directory’s descendants.

Command
onesource --no-config -i "src/**,README.md" -x "src/legacy/" --dry-run

Expect README.md, src/main.rs and src/util.rs: Files Processed: 3. old.rs matches include, but exclude wins. The tree inherits these filters, so legacy should disappear from it too. Once verified, write exactly that selection:

Command
onesource --no-config -i "src/**,README.md" -x "src/legacy/" -o review.onesource

Open review.onesource and confirm three file blocks. If you want excluded content to remain visible as structure, use the independent tree controls.

Learn to choose a glob pattern

A glob describes paths, not file contents. Use src/** for a subtree, *.rs for an extension, and an exact relative path for one file. ? matches one character; [ab] matches a listed character. For example, src/[mu]*.rs selects main.rs and util.rs in this fixture. Test patterns against actual paths rather than guessing.

Command
onesource --no-config -i "src/[mu]*.rs" --dry-run

Expect two content files. To stop restricting include altogether, pass an explicit empty string:

Command
onesource --no-config --include="" --dry-run

Expect README plus the four Rust files; notes remains ignored and .env remains blacklisted. An empty include means no include restriction, not an empty result. This also overrides a saved include when config loading is enabled.

Quote patterns to prevent shell expansion. Patterns are comma-separated, trimmed and backslashes are normalized to /. Empty entries are ignored; an empty list disables that filter. Globset supports *, ?, **, character classes and braces (avoid commas inside braces because the CLI splits commas first). Matching is case-sensitive. * may match across separators with the current default Glob settings. A trailing src/ becomes src/**. A simple name with no slash, star or dot, such as vendor, matches that name and descendants at any depth; names containing dots do not get this expansion. Invalid globs return an error.

3. Find out why include did not restore a file

Try asking for notes.txt explicitly:

Command
onesource --no-config -i "notes.txt" --dry-run

Expect zero processed files because .gitignore excludes notes.txt before it can be selected. Ask explain for the reason:

Command
onesource explain notes.txt --no-config -i "notes.txt"

Expected output / excerpt
Content:
  Result: blocked by ignore filters
Tree:
  Result: blocked by ignore filters

This is a report excerpt. --no-ignore disables the walker’s ignore rules; it does not remove the blacklist. If including the note is intentional, verify the change:

Command
onesource --no-config -i "notes.txt" --no-ignore --dry-run

Expect notes.txt and Files Processed: 1. If the result instead says blocked by blacklist or exclude, changing ignore alone cannot help. Resolve the reported rule first.

Current output is excluded independently. Standard walker filters honor .ignore, .gitignore, Git exclude/global and parent ignore rules, even outside a Git repository; hidden files are not automatically excluded. Blacklist wins over user globs; exclude wins over include. An include cannot restore an ignored or blacklisted path. Explain reports blacklist before ignore, then exclude, then include; content then checks file type, size, NUL bytes and readability. --no-ignore disables standard ignore filters; --no-blacklist is separate.

Understand and inspect the built-in blacklist

The blacklist protects common secret files, generated output and tool directories without needing project ignore rules. In this fixture .env holds a dummy value. Even with --no-ignore, it is still blocked:

Command
onesource explain .env --no-config --no-ignore

Expect blocked by blacklist with Rule: blacklist = .env. To inspect a deliberately allowed sample, disable this separate layer:

Command
onesource explain .env --no-config --no-ignore --no-blacklist

Expect included for both sections. This only diagnoses the sample and does not create a bundle. Do not carry --no-blacklist into a shared bundle without reviewing every selected path. The complete list follows:

Component names match case-insensitively anywhere in the path. Patterns match case-insensitively against the normalized path or filename. Disabling this list can include secrets and previous bundles; review the preview before sharing.

Reference
.git, .gitignore, .env, .onesourcerc, .svn, .hg, node_modules,
__pycache__, venv, .venv, .pytest_cache, .tox, target, .idea, .vscode,
.DS_Store, .npmrc, .pypirc, .netrc, id_rsa, id_dsa, id_ecdsa, id_ed25519

.env.*, credentials.json, service-account*.json, *.pem, *.key,
*.p12, *.pfx, *.onesource, .onesource-tmp-*, .onesource-backup-*