LoginSignup
50

More than 5 years have passed since last update.

.gitignoreを作成する前にgit addしてしまった場合

Posted at

どちらかというと個人的メモ。

現象

.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

これにて一件落着。

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
50