Harish
Harish

Reputation: 510

How to avoid node_modules that were not added to .gitignore to be deleted on pull?

By following this question (How to make Git “forget” about a file that was tracked but is now in .gitignore?) I was able to remove any node_modules that were included in the project from the index of git.

Although it is not tracked by git in my branch, it deletes the node_modules when someone pulls my branch.

Is there a possible solution to avoid this.

Upvotes: 0

Views: 57

Answers (1)

1615903
1615903

Reputation: 34739

Is there a possible solution to avoid this.

There is a way explained here (using .idea folder as an example):

If the other developers run git rm -r --cached .idea and commit that to their local trees before pulling your changes, Git will see that these two changes are equivalent (both "delete" the folder) and thus not try to delete it again.

And also a workaround:

If the folder gets deleted on their machine, they can simply restore it again. After all, this is version control!

There is the git checkout command that asks Git to place any file from any point in time in your current working copy. So if the last commit that your coworker pulled from you caused the .idea folder to be deleted, she could just say git checkout HEAD^ .idea and get it back from the version before. If there is more than one commit in between, first find the commit where the file has been deleted (git log --stat --diff-filter=D might be handy) and then use the commit before. So, for example, if the folder was deleted in commit c4f3d00d, use git checkout caf3d00d~1 .idea.

Upvotes: 1

Related Questions