LoginSignup
0
0

.gitignoreにプロジェクト内のnode_modulesを再帰的に全て追加する

Last updated at Posted at 2023-06-10

はじめに

プログラミング学習中の@kat_logと申します。

プログラミング学習中、学習中のプロジェクト(リポジトリ)の色んな階層にnode_modulesがある構成で、git管理に戸惑ったのですが、解決したため共有です。

image.png

結論

.gitignoreの再帰的な指定と、git rm -r --cached */node_modulesが必要でした。

設定

.gitignoreに以下を追加します

.gitignore
**node_modules

.gitignoreファイルはリポジトリ作成時に自動生成されるものではないため、存在しない場合はプロジェクトルート直下に自分で作成する必要があります

ターミナルにて、下記コマンドを実行します

このコマンドが必要なのは、/node_modulesが既にgit管理下に置かれてしまっている場合のみです

git rm -r --cached */node_modules

(追記)別の端末にてうまくいかない場合

別の端末にてコミットしようとした際
まだ上記の設定が反映されていないと、fatal: pathspec '*/node_modules' did not match any filesというエラーが出ます
その際は、

  1. git rm -r --cached .
  2. git add .
  3. git commit -m "Exclude node_modules directory"

とするとうまくいきました!

おわりに

お読みいただきありがとうございました。
自分用のメモ的な知識ですが、どなたかの参考になることがあれば嬉しいです。

参考

0
0
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
0
0