LoginSignup
8
9

More than 5 years have passed since last update.

すでにステージ上にあるファイルを.gitignoreに追加する

Posted at

先に結論

ファイル

git rm --cached [rmしたいファイル]
git add -A
git commit -m "add xxx to .gitignore"

ディレクトリ

git rm -r --cached [rmしたいディレクトリ]
git add -A
git commit -m "add xxx to .gitignore"

全部

git rm -r --cached . 
git add -A
git commit -m "update .gitignore"

git rmについて

① rmのみ

git rm text.php

ワーキングディレクトリおよびステージから削除。

② --cached

git rm --cached text.php

ステージから削除。ワーキングディレクトリには残っているのでgit addすればふつうにまたステージにあがる。
これは特にtext.phpを.gitignoreに追加したときにやるとよい。.gitignoreはワーキングディレクトリからステージにaddするときにフィルタとして通すので、一度ステージにあがってしまったものを.gitignoreにあげても無視されない。一度ステージから削除する必要がある.

③ -r --cahced

git rm -r --cached

ディレクトリをステージから削除するときは-rオプションをつける。

8
9
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
8
9