github/gitignore · Ruby.gitignore
Ruby .gitignore 模板详解
说明 Ruby.gitignore 忽略 gem 包、Bundler 安装目录、测试结果和文档生成物的原因,以及 Gemfile.lock、.ruby-version 的提交标准。
Ruby.gitignore 面向制作 gem 或开发 Ruby 脚本、应用程序的项目。大多数规则以 / 开头并固定在仓库根目录,因此很少会误忽略同名的子目录。
如果是 Rails 应用,Rails 模板比这个模板覆盖更多情况。同时选择两者时,重叠的规则会通过去重整理。
逐条规则详解
| 模式 | 忽略什么,为什么忽略 |
|---|---|
*.gem/pkg/ | gem 包gem build 和 rake build 生成的包文件,是发布到 RubyGems 的产物。 |
/.bundle//vendor/bundle/lib/bundler/man/ | Bundler.bundle/ 中存放本地 Bundler 配置,vendor/bundle 中存放用 bundle install --path 安装的 gem。可以在其他电脑上重新安装。 |
/coverage//spec/reports//spec/examples.txt/test/tmp//test/version_tmp/ | 测试结果SimpleCov 结果、RSpec 报告,以及 RSpec 用来记录失败示例的 examples.txt 等运行结果。 |
/.yardoc//_yardoc//doc//rdoc/ | 文档生成物YARD、RDoc 生成的 API 文档和缓存,可以从源码注释重新生成。 |
/tmp/.byebug_history.repl_history*.rbc/.config/InstalledFiles | 临时与调试器文件临时目录、byebug 与 REPL 历史、Rubinius 字节码以及 setup.rb 安装记录。 |
.rvmrc | 版本管理器配置RVM 的旧式项目配置文件,可以执行 shell 代码,因此避免共享。如今主要使用 .ruby-version。 |
实践中的注意事项
- 按照模板注释,应用程序提交
Gemfile.lock和.ruby-version,而会在多种环境中使用的库(gem)有时会忽略它们。 /doc/会忽略根目录下整个doc目录。如果手写文档放在doc/中,请删除这一行,并像/doc/api/这样只指定生成路径。.env规则在此模板中只以注释形式存在,如果使用环境变量文件,请自行添加。
原始模板
Ruby.gitignore
*.gem*.rbc/.config/coverage//InstalledFiles/pkg//spec/reports//spec/examples.txt/test/tmp//test/version_tmp//tmp/# Used by dotenv library to load environment variables.# .env# Ignore Byebug command history file..byebug_history## Specific to RubyMotion:.dat*.repl_historybuild/*.bridgesupportbuild-iPhoneOS/build-iPhoneSimulator/## Specific to RubyMotion (use of CocoaPods):## We recommend against adding the Pods directory to your .gitignore. However# you should judge for yourself, the pros and cons are mentioned at:# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control## vendor/Pods/## Documentation cache and generated files:/.yardoc//_yardoc//doc//rdoc/## Environment normalization:/.bundle//vendor/bundle/lib/bundler/man/# for a library or gem, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# Gemfile.lock# .ruby-version# .ruby-gemset# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:.rvmrc# Used by RuboCop. Remote config files pulled in from inherit_from directive.# .rubocop-https?--*
模板来源: github/gitignore/Ruby.gitignore @356fd7b (2026-09-11) · CC0-1.0