LoginSignup
34
33

More than 5 years have passed since last update.

ローカル環境の設定ファイルをgitの対象から外す

Last updated at Posted at 2014-06-08

ローカルで作業をするときに、

fuel/app/config/development/db.php

で設定を変更しました。
また、
http://qiita.com/maximum80/items/729af0392a84a3196088
で書かれているように、composerのアップデートを行いました。

その後にリモートの最新状態をpullしようとすると、

Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.

とgitに怒られてしまいます。

でも、ローカルでの開発用に設定しているファイルなので、この子達はコミットしたくありません。
そんな時の対処法です。

1. git rm --cached ファイル名

まず、

$ git status
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   composer.phar
    modified:   fuel/app/config/development/db.php

と、ステージングをしていないファイルが2つあります。
これらのファイルの変更履歴をgitから削除しましょう。

$ git rm --cached fuel/app/config/development/db.php
$ git rm --cached composer.phar

これで、変更をしたという履歴がgitから削除されます。

2. .gitignoreに指定のファイルを追記

.gitignoreは、
gitに無視をさせるファイル(変更をしても無視をする)ファイルを指定するファイルのことです。

$ vim .gitignore
/fuel/app/config/development/db.php
composer.phar

と、変更を無視したいファイルを追記すればオーケー。

$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 131 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working directory clean

となっていれば完了。

[参考URL]
http://www.omakase.org/misc/gitignore.html

34
33
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
34
33