Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git advanced ignoring [duplicate]

Tags:

git

gitignore

My .gitignore looks more less like this:

# Ignore everything
*

# But not these files...
!.gitignore
!ImportantDirectory/
!AnotherImportantDirectory

# Actually, ignore these...
ImportantDirectory/NotImportantFile

The problem is that ImportantDirectory/NotImportantFile is still being tracked. Any idea how to solve this?

like image 816
mpiekarz Avatar asked Oct 30 '25 16:10

mpiekarz


1 Answers

If you had previously included that file, it will continue to be tracked until you remove it from your repository, even if you list it in a .gitignore. Sounds like that is what is happening here. You can do that with:

git rm --cached ImportantDirectory/NotImportantFile

Note this will remove the file from the .git repository, but will not delete the local file on disk. Note however this will delete ImportantDirectory/NotImportantFile for anyone who pulls your git repository, so if this is a file they also need to maintain, but not have included, you may need to take a different approach.

like image 146
Duncan Babbage Avatar answered Nov 02 '25 09:11

Duncan Babbage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!