Reputation: 3262
My .gitignore contains the following:
deploy/media/customoptions/options/*/*/70x/*
deploy/media/customoptions/options/*/*/200x/*
deploy/media/customoptions/options/*/*/*/*
I realize this is a bit more then it really needs, but I've been testing different patterns to try to get it working.
When I run an add command:
git add deploy/media/customoptions/ --verbose --dry-run
One of the files it's matching I would like to be ignored. Why is this being added? Based on the path, it should match true above.
deploy/media/customoptions/options/998/4325/200x/200-ntlrope.jpg
I have tried deleting the entire .git directory and git init
ing it again to start from a blank slate, and still adds that file.
Upvotes: 1
Views: 146
Reputation: 5996
As the answers already given describe that it should work, here are two ideas on what could have gone wrong:
deploy/media/customoptions/options/998/4325/200x/200-ntlrope.jpg
in your repository, git add
will happily stage the changes of this file to the index. Either you remove the file from the repository (git rm --staged <filename>
) or you tell Git to never check for modifications of this file (git update-index --assume-unchanged <filename>
)..gitignore
? Paths are always relative to the directory of this file. So you may put the file in the directory deploy/media/customoptions/
and add options/
to it to ignore the directory deploy/media/customoptions/options
and all its content. Or you may put it in the root of your repository with the full path deploy/media/customoptions/options/
.Upvotes: 0
Reputation: 3628
Works with my test using what I mentioned in my comments:
➜ ~ mkdir test
➜ ~ cd test
➜ git init
Initialized empty Git repository in /home/jhvisser/test/.git/
➜ mkdir deploy/media/customoptions/options/998/4325/200x/ -p
➜ echo "test" > deploy/media/customoptions/options/998/4325/200x/200-ntlrope.jpg
➜ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
deploy/
nothing added to commit but untracked files present (use "git add" to track)
➜ git add deploy/media/customoptions/ --verbose --dry-run
add 'deploy/media/customoptions/options/998/4325/200x/200-ntlrope.jpg'
➜ echo "deploy/media/customoptions/options/*" > .gitignore
➜ cat .gitignore
deploy/media/customoptions/options/*
➜ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
➜ git add deploy/media/customoptions/ --verbose --dry-run
➜
Therefore try just deploy/media/customoptions/options/*
I also tested with deploy/media/customoptions/options/*/*/200x/*
and deploy/media/customoptions/options/*/*/*/*
and both of these worked. These are the ones you show in your examples. You may be doing something incorrect, so give what I showed in my test a try.
Upvotes: 1
Reputation: 15143
First of all, you shouldn't have to delete the .git
directory to re-set ignored files. The following two commands should re-set everything and ignore the relevant pieces from the .gitignore
:
git rm -r --cached .
git add -A
That will first "remove" everything from Git and then re-add it back, obeying .gitignore
files.
As far as your patterns, it appears you're attempting to just ignore everything after
deploy/media/customoptions/options
in which case you could use the globstar pattern
deploy/media/customoptions/options/**/*
or simply just 'anything' under options/
deploy/media/customoptions/options/*
Remember that *
matches directories too, and Git supports ignoring whole directories, so even the following should work
deploy/media/customoptions/options/
Upvotes: 0