github/gitignore · Rust.gitignore
Rust .gitignore Template Explained
Why Rust.gitignore ignores the target directory, rustfmt backups, MSVC debug info and cargo-mutants output, and the change to recommend committing Cargo.lock.
Rust.gitignore is a short template containing only the minimum rules a Cargo project needs. Most output ends up in a single target/ directory, so there are few rules.
The old template told you to ignore Cargo.lock for libraries, but the current template no longer has that rule. In 2023 the Rust team changed its recommendation and made committing Cargo.lock the default for all projects, including libraries.
Rules explained
| Pattern | What it ignores and why |
|---|---|
targetdebug | Cargo build outputThe folder where cargo build puts compilation results, incremental build caches and built dependencies. It can grow to several GB and is fully regenerated. Without a trailing /, files with the same name are ignored too. |
**/*.rs.bk | rustfmt backupsBackups that rustfmt leaves before modifying a file. The pattern starts with **/, so it matches at any depth. |
*.pdb | MSVC debug informationDebug symbol databases created when building with the Windows MSVC toolchain. |
**/mutants.out*/ | Mutation testing outputOutput directories created by cargo-mutants (mutants.out, mutants.out.old). Because of the trailing /, the pattern matches only directories. |
rustc-ice-*.txt | Internal compiler error dumpsStack traces that rustc leaves in the current directory when it hits an internal compiler error (ICE). They are useful for bug reports but not needed in the repository. |
Practical notes
- Commit
Cargo.lock. Cargo's current default recommendation is to commit it for libraries too, for reproducible builds and consistent CI results. - In a workspace, a single
target/is created at the workspace root, but because thetargetrule has no slash, it is ignored wherever it appears. - Handle RustRover and IntelliJ settings separately with the JetBrains template. The template comments also note that ignoring the whole
.idea/is not recommended.
Original template
Rust.gitignore
# Generated by Cargo# will have compiled files and executablesdebugtarget# These are backup files generated by rustfmt**/*.rs.bk# MSVC Windows builds of rustc generate these, which store debugging information*.pdb# Generated by cargo mutants# Contains mutation testing data**/mutants.out*/# rustc will dump stack traces when hitting an internal compiler error to PWDrustc-ice-*.txt# RustRover# JetBrains specific template is maintained in a separate JetBrains.gitignore that can# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore# and can be added to the global gitignore or merged into this file. For a more nuclear# option (not recommended) you can uncomment the following to ignore the entire idea folder.#.idea/
Templates from github/gitignore/Rust.gitignore @356fd7b (2026-09-11) · CC0-1.0