4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Gitに管理されたファイルを削除したい

Last updated at Posted at 2020-10-21

.gitignoreに書き忘れてcommitしてしまった時に、
「.gitignoreに追記すれば大丈夫...」
と誤解していませんか?
僕のように..汗

後から.gitignoreに追記するだけではすでにGitに管理されたファイルは除去されないので、そんな時の対処方法を書いておきます。

Gitに管理されたファイルを残して除外したい場合

$ git rm --cached [除外したいファイル名]

その後は必ず.gitignoreに除外したいファイルを追記する。
注意箇所:
--cachedを必ずつける!!
つけないとファイルごと削除してしまいます。

ファイルごと削除したい場合

$ git rm [削除したいファイル名]

ディレクトリごと削除したい場合

$ git rm -r [削除したいディレクトリ]

最後に

Gitを使い始めた時に何回か忘れてcommitして、都度調べていたので備忘録として残しておきます。

同じ境遇になった方のお役に立てば嬉しいです。

4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?