user2297392
user2297392

Reputation:

.gitignore is ignoring other directories with the same name

I have a problem in my .gitignore. I want it to just ignore the 'vendor/' directory, but it is ignoring all directories with that name.

Below is my .gitignore:

.idea/ 
bin/ 
vendor/ 
composer.lock 
composer.phar 

Below is the result of my 'git status':

Changes not staged for commit: 
   (use "git add <file> ..." to update what will be submitted) 
   (use "git checkout - <file> ..." to discard changes in working directory) 

modified: .gitignore 

Not monitored files: 
   (use "git add <file> ..." to include what will be submitted) 

src/vendor/ 
tests/src/ 
vendor/ 

It is also ignoring 'src/vendor', I do not want that to happen, I want it to ignore 'vendor/'

Upvotes: 39

Views: 15391

Answers (2)

Andrew C
Andrew C

Reputation: 14883

From the docs for Git Ignore

A leading slash matches the beginning of the pathname. For example, /*.c matches cat-file.c but not mozilla-sha1/sha1.c.

Try changing vendor/ to /vendor/

Upvotes: 63

Justin
Justin

Reputation: 2031

From Git - gitignore Documentation:

"If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in Git)."

"If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file)."

Simply remove the /

.idea 
bin 
vendor 
composer.lock 
composer.phar 

Upvotes: 4

Related Questions