EmmyS
EmmyS

Reputation: 12138

How to I remove files from .gitignore?

I've found all kinds of answers about how to add files to .gitignore (i.e. make git ignore files that were previously tracked), but I can't seem to figure out the reverse.

I have a .gitignore that has certain files in it being ignored that I no longer want to be ignored. I've removed the files from the .gitignore file, but they're still being ignored when I do commits. What do I need to do to make git start tracking these files again?

Upvotes: 2

Views: 279

Answers (3)

Nadav
Nadav

Reputation: 1145

Once you remove a file from the .gitignore list Git will stop ignoring it. However, if it has been ignoring it thus far it will not recognize any changes made to that file while it was ignored. To make those changes apparent to Git, make at least one more change to that file after delisting it.

As a side-note, you do not need to commit .gitignore in order for changes made to it to take affect locally.

Upvotes: 1

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

Places to Check for Ignored Files

In addition to your repository's .gitignore file, you may also have things ignored in a global ~/.gitignore or $HOME/.config/git/ignore, or in the repository's .git/info/exclude file. You should ensure all of them have been updated, and that your file is not listed in any of them.

Also check the value of core.excludesfile (see git-config) both globally and locally to see if you have it set to something custom. And finally, you can check whether a particular file is really being ignored and where that's been specified by using git-check-ignore. For example:

git check-ignore --verbose <some_file>

Upvotes: 4

Chan Kha Vu
Chan Kha Vu

Reputation: 10390

Write git add file_that_you_want_to_include in console for each file that you want to be included, or just git add -A - it will include all files, except files mentioned in .gitignore. And don't forget to commit your .gitignore file.

Upvotes: 1

Related Questions