Exact way to ignore / not write files in git
In my project, I have a gitignore file that nicely has an instruction to ignore node_modules like:
########################
# node.js / npm
########################
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
logs
results
node_modules
It works as expected. Git doesn't see changes inside node_modules.
I have changes to a file inside node_modules that I would like to include in further commits as it will definitely change. But at the same time, I want the rest of the node_modules to be ignored. This is an example of what I need for "unignore":
node_module/passport-saml/saml.js
I had the same problem a while ago. I followed some instructions on how to do it, but I ended up creating a mess ... I remember I was using Git uncheck / untrack or something similar. It took me longer to fix what I broke by trying to "not write" the file. I ended up manually changing the line of code to git.
This time, I really would like to get it right.
source to share
You don't need to add any special exception, git already handles this once the file has been added once.
To add a file that matches the filter in yours .gitignore
, just force it by adding the parameter -f
:
git add -f node_module/passport-saml/saml.js
After adding a file, it will be tracked like any other file, even if the ignore filter matches.
Just change it and then add it as usual:
git add node_module/passport-saml/saml.js
What is it. There is no need for any special rules or exceptions.
source to share
You can add this file and start tracking it with the option --force
:
git add --force node_module/passport-saml/saml.js
From the git add
man page :
-f
--force
Allow adding ignored files.
source to share