github/gitignore · Ruby.gitignore

Ruby .gitignore 模板详解

说明 Ruby.gitignore 忽略 gem 包、Bundler 安装目录、测试结果和文档生成物的原因,以及 Gemfile.lock、.ruby-version 的提交标准。

在生成器中打开 与 Rails, macOS, JetBrains 一起打开

Ruby.gitignore 面向制作 gem 或开发 Ruby 脚本、应用程序的项目。大多数规则以 / 开头并固定在仓库根目录,因此很少会误忽略同名的子目录。

如果是 Rails 应用,Rails 模板比这个模板覆盖更多情况。同时选择两者时,重叠的规则会通过去重整理。

逐条规则详解

模式忽略什么,为什么忽略
*.gem/pkg/gem 包gem buildrake 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

实践中的注意事项

原始模板

Ruby.gitignore规则 26 行
*.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

常搭配使用的模板

其他模板详解