I
I
Igor2019-02-08 23:03:41
git
Igor, 2019-02-08 23:03:41

How to locally ignore a folder in git so that when it is subsequently changed, it no longer gets into the index?

Hello!
There is a module folder in the git. There is no way I can influence and remove it from there.
But I need to work on a project. On my machine, I need to install my modules because of the difference in the operating system.
Accordingly, I should not send modules to the master branch, because I work only with those that are.
And the update is handled by a separate person.
The question is, can I somehow ignore the modules so that git stops tracking them?
I tried to add the modules folder to the local ~/.gitignore
Also remove git rm -r --cached node_modules
but after installing my own modules, git prompts me to add them to the commit and remove them from the index
Of course, the way out is simply not to add them to the commit, of course you can live, but it's very inconvenient
. Maybe someone will advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Deyashkin, 2019-02-14
@Lobotomist

In general, the situation looks strange and node_modules most likely needs to be removed from the repository. Further to the essence of the issue.
In order to prevent new modules from being tracked by git, the easiest option is to add ignoring them for a specific repository (will only work for your local repository) in the .git/info/exclude file, write:
Also, to solve this problem, you can install modules in other folders, see the documentation for options , there are many of them, I won’t give them.
It's more difficult if you're modifying module files already tracked by git. To keep your changes from being tracked by git, you can tell it to ignore changes to them. There is a command for this git update-index --skip-worktree <path>. You can run it immediately for all files in the node_modules folder , or you can selectively only for those that are actually changed.

# для всех
git ls-files node_modules | xargs git update-index --skip-worktree
# для измененных
git ls-files -m node_modules | xargs git update-index --skip-worktree

git ls-files node_modules- lists the files monitored by git in the node_modules folder, with the -m switch only those that are modified.
xargs- executes the corresponding command for each of these files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question