github/gitignore · Rust.gitignore

Rust .gitignore テンプレート解説

Rust.gitignore が target ディレクトリ、rustfmt のバックアップ、MSVC のデバッグ情報、cargo-mutants の結果を無視する理由と、Cargo.lock のコミットを推奨する方針変更を説明します。

ジェネレーターで開く VisualStudioCode, JetBrains, macOS と一緒に開く

Rust.gitignore は Cargo プロジェクトに必要な最小限のルールだけを含む短いテンプレートである。ほとんどの成果物が target/ 1 つに集まるため、ルール数が少ない。

以前のテンプレートはライブラリの場合 Cargo.lock を無視するよう案内していたが、現在のテンプレートにそのルールはない。Rust チームは 2023 年に推奨事項を変更し、ライブラリを含むすべてのプロジェクトで Cargo.lock のコミットを基本とした。

ルール別の解説

パターン何を、なぜ無視するか
targetdebugCargo ビルド結果cargo build がコンパイル結果、インクリメンタルビルドのキャッシュ、依存関係のビルド物を入れるフォルダーである。数 GB にまで大きくなることがあり、完全に再生成される。末尾に / がないため、同名のファイルも無視される。
**/*.rs.bkrustfmt バックアップrustfmt がファイルを修正する前に残すバックアップである。**/ で始まるため、あらゆる深さで一致する。
*.pdbMSVC デバッグ情報Windows の MSVC ツールチェーンでビルドするときに生成されるデバッグシンボルのデータベースである。
**/mutants.out*/ミューテーションテスト結果cargo-mutants が作る結果ディレクトリ(mutants.outmutants.out.old)である。末尾の / によりディレクトリにのみ一致する。
rustc-ice-*.txtコンパイラー内部エラーのダンプrustc が内部コンパイラーエラー(ICE)に遭遇したときにカレントディレクトリへ残すスタックトレースである。バグ報告には使うが、リポジトリには不要である。

実務での注意点

元のテンプレート

Rust.gitignoreルール 6 行
# 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/

テンプレートの出典: github/gitignore/Rust.gitignore @356fd7b (2026-09-11) · CC0-1.0

一緒に使うテンプレート

ほかのテンプレートの解説