Exact way of ignore/unignore files in git

In my project I have a gitignore file, that nicely has statement to ignore node_modules, such as:

########################
# node.js / npm
########################
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz


logs
results

node_modules

It works just as expected. Git does not see any change within node_modules.

  • Recover deleted local repository, got source files with file recovery but not recognizing as Git
  • How to use code libraries from github?
  • Visual Studio 2015 using Git unable to compare files
  • Prefabs & scripts missing after using source control to move Unity project to a different machine
  • Meld installed with Homebrew “Can't bind translation domain” Error
  • Creating a copy of local git repository on a remote server
  • I have changes in a file within node_modules that I would like to include in further commits, as it will change definitely. But at the same time I want to keep the rest of the node_modules ignored.
    This is example of what I need to “unignore”:

     node_module/passport-saml/saml.js
    

    Some time ago, I had the same issue. I have followed some instructions how to do it, but I ended up creating a mess… I remember I used git uncheck / untrack or something similar. It took me more time to fix the thing I broke while trying to “unignore” the file. At the end, I ended up manually changing the line of code on the git.

    This time I really would like to do it properly.

  • git ignore line endings
  • reverting to previous change in bitbucket
  • Fetching specific deleted commit from git
  • Git-Diff vs. Git-log? What's the difference?
  • What does 'adding to the index' really mean in Git?
  • Intellij git revert a commit
  • 3 Solutions collect form web for “Exact way of ignore/unignore files in git”

    You won’t have to add any special exception, git already handles that, once the file has been added once.

    To add a file that fits a filter in your .gitignore, just force it by adding the -f param:

    git add -f node_module/passport-saml/saml.js
    

    Once the file is added, it will be tracked like any other file, even though the ignore filter matches.

    Just change it and then add it as usual:

    git add node_module/passport-saml/saml.js
    

    That’s it. No need for any special rules or exceptions.

    You can add that file, and start tracking it with the --force option:

    git add --force node_module/passport-saml/saml.js
    

    From git add man page:

    -f
    --force
    

    Allow adding otherwise ignored files.

    You can use ! before path in your .gitignore file to invert the pattern:

     !node_module/passport-saml/saml.js
    

    From man page:

    An optional prefix “!” which negates the pattern; any matching file
    excluded by a previous pattern will become included again

    Git Baby is a git and github fan, let's start git clone.