LoginSignup
13
24

More than 3 years have passed since last update.

【Rails】.gitignoreの設定について

Last updated at Posted at 2020-06-13

経緯

先日、Gitにcommitする際に余計なファイルまで上がってしまって苦しんだのですが、
すごく便利な.gitignoreの設定方法を教えていただいたので、共有します。

giboってしってるかい?

こいつ、.gitignoreを自動で生成してくれんです。

インストール

$ brew install gibo

gitignoreの生成

$ gibo Rails

これだけ。
こんな感じで生成されます。↓↓

/.bundle
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
.byebug_history
.DS_Store### https://raw.github.com/github/gitignore/18aa6d83774d514da479d73a4beb864cd4220231/Rails.gitignore
.rbc
capybara-.html
.rspec
/db/
.sqlite3
/db/.sqlite3-journal
/db/
.sqlite3-[0-9]*
/public/system
/coverage/
/spec/tmp
.orig
rerun.txt
pickle-email-
.html
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
.env
.env.*
/.bundle
/vendor/bundle
.rvmrc
.bowerrc
bower.json
.powenv
.byebug_history
/public/packs
/public/packs-test
/public/assets
/yarn-error.log
yarn-debug.log*
.yarn-integrity
/storage/*
!/storage/.keep
/public/uploadse/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

(コメントアウトの部分とかは削除してます。)
これ、すごくないですか!
初心者の友、DS_Storeに悩まされることは、もうありませんね。

$ gibo Rails >> .gitignore

このコマンドで.gitignoreに突っ込んで終了。

おまけに

$ gibo -l
=== Languages ===

Actionscript        EPiServer       Lua         Scala
Ada         Erlang          Magento         Scheme
Agda            ExpressionEngine    Maven           SCons
Android         ExtJs           Mercury         Scrivener
AppceleratorTitanium    Fancy           MetaProgrammingSystem   Sdcc
AppEngine       Finale          Nanoc           SeamGen
ArchLinuxPackages   ForceDotCom     Nim         SketchUp
Autotools       Fortran         Node            Smalltalk
C++         FuelPHP         Objective-C     Stella
C           Gcov            OCaml           SugarCRM
CakePHP         GitBook         Opa         Swift
CFWheels        Go          OpenCart        Symfony
ChefCookbook        Gradle          OracleForms     SymphonyCMS
Clojure         Grails          Packer          Terraform
CMake           GWT         Perl            TeX
CodeIgniter     Haskell         Phalcon         Textpattern
CommonLisp      Idris           PlayFramework       TurboGears2
Composer        IGORPro         Plone           Typo3
Concrete5       Java            Prestashop      Umbraco
Coq         Jboss           Processing      Unity
CraftCMS        Jekyll          PureScript      UnrealEngine
CUDA            Joomla          Python          VisualStudio
D           Julia           Qooxdoo         VVVV
Dart            KiCad           Qt          Waf
Delphi          Kohana          R           WordPress
DM          LabVIEW         Rails           Xojo
Drupal          Laravel         RhodesRhomobile     Yeoman
Eagle           Leiningen       ROS         Yii
Elisp           LemonStand      Ruby            ZendFramework
Elixir          Lilypond        Rust            Zephir
Elm         Lithium         Sass

=== Global ===

Anjuta          Ensime          Mercurial       SVN
Ansible         Espresso        MicrosoftOffice     SynopsysVCS
Archives        FlexBuilder     ModelSim        Tags
Bazaar          GPG         Momentics       TextMate
BricxCC         JDeveloper      MonoDevelop     TortoiseGit
Calabash        JEnv            NetBeans        Vagrant
Cloud9          JetBrains       Ninja           Vim
CodeKit         Kate            NotepadPP       VirtualEnv
CVS         KDevelop4       Otto            VisualStudioCode
DartEditor      Lazarus         Redcar          WebMethods
Dreamweaver     LibreOffice     Redis           Windows
Dropbox         Linux           SBT         Xcode
Eclipse         LyX         SlickEdit       XilinxISE
EiffelStudio        macOS           Stata
Emacs           Matlab          SublimeText

私が紹介したものはRails用でしたが、他の言語でも使えるようですね!!すごい

.gitignoreで設定したのにcommitされちゃう!?

実は、既にcommit等してGitの管理下に置かれてしまったファイルは、
.gitignoreで設定してもcommitに上がり続けてしまいます

後から、対象から外したくなったら以下のコマンドを実行してみてください。

$ git rm -r --cached . //ファイル全体キャッシュ削除
$ git rm -r --cached [ファイル名]  //ファイル指定してキャッシュ削除

.gitignoreで設定しているファイルが、Git上から抹消されますので。

13
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
24