问题
I am trying to push my project to github and heroku. Since I am using nodejs in my app , I have node_modules. Before I commit I have created a file called .gitignore
to ignore the node modules.
Inside the file I have added node_modules and tried to push to the GitHub from the comandline/Terminal. I was not expecting the node modules to be push but they appeared finally in the repo. Is there any ways i have to follow , i need help in this regards; thanks!
Here is how I resolve my issue
- $ git rm -r --cached node_modules
add node_modules/ to your .gitignore file
- $ git commit -m "remove the ignored directory node_modules"
and then
- $ git push origin master
After that , if you refresh the GitHub page you will see the node_modules gone.
回答1:
The node_modules
folder should be added to the .gitignore
file.
First, get rid of your node_modules
:
$ git rm -r --cached node_modules
$ git commit -m "remove node_modules"
Then, push your change
$ git push origin master
Refresh the page to see the desired effect.
回答2:
First thing you will need to add node_modules inside your .gitignore
file
then
$ git rm -r -chached node_modules
$ git commit -m "remove node_modules"
and then
$ git push origin master
Hope this will work
回答3:
Just in case, the .gitignore
file, is inside the node_modules
or in the root of the project?
If so, I'll recommend to place it [at least] in a parent folder, or ideally in the project's root, and inside it call node_modules
as a relative path to the location of the file. i.e: some-path/node_modules
.
Besides that, once the folder is commited and pushed, you should ignore the gitignore (by deleting it temporarily or deleting the node_modules line) so git can keep track of the files, delete the folder, commit, push, and restore the gitignore.
回答4:
You have to tell Git to untrack the files that have been already added to Git (before you ignored them):
git rm --cached FILE
FILE won't be deleted from your filesystem. Git will untrack this fille, and since it's ignored, it won't be tracked anymore.
Then, of course you have to commit and push this change.
来源:https://stackoverflow.com/questions/44168609/node-modules-pushed-to-github