どちらかというと個人的メモ。
現象
.gitignoreを作成する前にnpm install
をしてしまい、git add .
でnode_modules以下を全てインデックスに登録してしまった。
やりたいこと
インデックスからnode_modules以下を全て消したい。
手順
まずはミスってしまった経緯
$ git add .
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: app.js
new file: index.jade
new file: node_modules/.bin/jade
new file: node_modules/express/History.md
new file: node_modules/express/LICENSE
new file: node_modules/express/Readme.md
new file: node_modules/express/index.js
new file: node_modules/express/lib/application.js
.
.
.
.gitignoreを作成する
$ subl .gitignore
node_modules/
インデックスからnode_modules以下を削除する
$ git rm -r --cached node_modules
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: app.js
new file: index.jade
new file: package.json
この段階で、再び登録しようとしてもnode_modules以下は登録されなかった。
$ git add .
$ git status
これにて一件落着。