2

I have a Node.js project and have imported a few Node modules. The git_status command shows the files that I changed in the project. I have also changed some files under the node_modules directory but those are not shown. The node_modules directory is shown as untracked.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

node_modules/
src/js/main-release-paths.json

I have changed only one file in node_modules:

node_modules/@oracle/grunt-oraclejet/node_modules/@oracle/oraclejet-tooling/lib/serve/connect.js

How can I track this file?

Adam Liss
  • 47,594
  • 12
  • 108
  • 150
Chirayu Sharma
  • 75
  • 1
  • 11

5 Answers5

3

You shouldn't add the node_modules folder to git then it's managed bei the npm command. So remove that folder and use the npm install command.

When you have added something in that folder it's shown as changed, if you had first added some files. So i hop that folder is in your .gitignore file and ignored. You should check that.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
2

Assuming you have git repo, Please check the .gitignore files inside your project. Entries in .gitignore will be ignored by Git and will not show up when you do git add.

dresh
  • 383
  • 1
  • 11
  • 18
1

Adding the file to track

This is most likely not a suitable approach (read below). However , if you really want to do it:

In order to track a file nested under node_modules, you should add the directory. All of its content will be staged in git

git add node_modules

Recommended approach

You probably don't want to track the contents of node_modules directory, because:

  • running npm install will wipe your changes
  • hundreds or thousand files are likely to end up present in that directory
  • tracking package.json and package-lock.json in git is sufficient, then populate node_modules using npm install command.

You are not supposed to modify files located in node_modules directory directly. Instead, fork the module in question, modify it, and:

  • either publish your own version in npm
  • or reference it as a git repository inside package.json (how-to)

Then, also add node_modules directory to the .gitignore file.

Mehdi
  • 7,204
  • 1
  • 32
  • 44
0

If the whole directory is untracked, git status will show only the directory. Because it's untracked, there is no meaningful difference to git between changed and unchanged files in there.

Other answers have already addressed that tracking node_modules is nota good idea. Of you want to track your changes to modules, consider cloning the module repo and including it as a git submodule.

OhleC
  • 2,821
  • 16
  • 29
0

It should be inside .gitignore file. A .gitignore file should be committed into your repository, in order to share the ignore rules with any other users that clone the repository.

Jithin Babu
  • 79
  • 1
  • 7