4

I just did a git commit and it deleted a few files seemingly randomly from my node_modules folder. Has anyone had this issue?

To be clear, my latest git commit deleted

delete mode 100644 node_modules/grunt-google-cdn/node_modules/google-cdn/node_modules/cdnjs-cdn-data/external/cdnjs.json

 delete mode 100644 node_modules/grunt-node-inspector/node_modules/node-inspector/front-end-node/Images/src/favicon.eps

 delete mode 100644 node_modules/moment/min/tests.js

 delete mode 100755 node_modules/requirejs/bin/r.js

I've never seen this before and I can't begin to understand why this happened. This prevents me from building my app for deployment. Does anyone know how/why this happened and how this can be prevented in the future?

rashadb
  • 2,515
  • 4
  • 32
  • 57

3 Answers3

1

My expectation is that those files were deleted at some point (via what mechanism, I can't say).

If you're using Git 2.0 or greater, when you typed git add ., you staged the deleted files for commit. git add . basically says "I want to stage all of the changes in this repo", which in this case included deleting files.

The behavior was different in prior versions (I just validated different behavior against Git 1.9 and 2.6.3).

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • Thanks for the suggestion but I did not touch those files. They're in an obscure location doing something not relevant to development save for the fact that there may be an error that causes me to have to look them up. Any other suggestions for the mechanism by which they could've been tampered with? – rashadb Dec 09 '15 at 02:59
  • 1
    @rashadb Sorry, I can't speculate as to what altered your file system. You asked why the deletions were committed -- now you know. You staged them. Git didn't remove them from your file system. – Daniel Mann Dec 09 '15 at 03:14
  • not really a satisfactory answer as I took no action specific to any of those files. I'm left to speculate how that may have occurred. – rashadb Dec 09 '15 at 03:17
1

I only did git add . beforehand

So you asked Git to stage everything in . (the current directory). This includes deleted files:

e.g. specifying dir will record not just a file dir/file1 modified in the working tree, a file dir/file2 added to the working tree, but also a file dir/file3 removed from the working tree

If these files were deleted by some non-git process and you subsequently ran git add . and then committed, the deletes would have been committed.

Comparing the documentation for version 1.9.2 and version 2.0.0 of git-add shows that this behaviour changed in version 2.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
1

To tell git to ignore deleted file(s) in the commit and commit all the other changes:

git add --ignore-removal .
vahid-dan
  • 252
  • 2
  • 8