.gitignore の設定を反映させる

はてなブックマーク - .gitignore の設定を反映させる
LINEで送る
Pocket

.gitignoreを更新したのに、なぜ反映されないというのが、ほぼ全員が避けて通らない道のようで(私はそうでした)この記事は短いですが、.gitignoreファイルを更新した(例えば新しいルールの追加)あとそれを反映させる方法を説明します。

目次

一括更新の場合

.gitignoreファイルを更新したとき

すでにリポジトリにignoreファイルを追加していると

キャッシュが残っていて

.gitignoreファイルの内容が反映されないことがよくあります。

そういうとき、便利なコマンドは

git rm -r --cached .
git add .
git commit -m ".gitignore is now updated"
git push origin master

ファイルのみの場合

一つのファイルだけ、管理対象から外したい場合は

git rm --cached [ファイル名]

上のようなコマンドで、管理対象除外できます。

ファイルの削除ではありません!

フォルダのみの場合

フォルダ(例えば __pycache__など)の場合

明示的に削除しないと、管理対象除外できない場合があります。

git rm -r /abc/efg/__pycache__/

その場合は、上記コマンドで、個別に、フォルダを管理対象から削除する必要があります。

フォルダの削除ではありません。

ちなみに全てのフォルダから、__pycache__を除外するというのは

**/__pycache/__

を.gitignoreファイルに追加すると良いでしょう。

 

最後

いかがですか?

これで、.gitignoreの設定が反映されたでしょうか?

意外と、癖のあるところかもしれません。

 

 

はてなブックマーク - .gitignore の設定を反映させる
LINEで送る
Pocket

Add a Comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close