José Carlos
José Carlos

Reputation: 2932

How to exclude files and directories in Git?

I'm working with Git version 2.11.0 and I don't know how exactly ignore some files and directories from my project.

In my project I've got a /vendor directory and inside of if files and other directories:

/vendor
/vendor/autolofile.php
/bin
/composer
/container-interop
/Demo
/psr
/zendframework
/zfcampus

Right now, I've got ignored all the /vendor directory and her files and subdirectories. But I want to exclude the file "autoload.php" and all the files that are inside of this directories structure:

/vendor/Demo/library/BBDD
/vendor/Demo/library/Data
/vendor/Demo/library/File

Now, I'm trying to see in status only all the files that are inside /vendor/Demo/library/BBDD but I'm not getting what I want. I've got this exit from git status command:

enter image description here

And what I have in my .ignore file is:

.vagrant/
vendor/*
!vendor/Demo
!vendor/Demo/library
!vendor/Demo/library/BBDD
!vendor/Demo/library/BBDD/*
config/development.config.php
data/cache/*
!data/cache/.gitkeep
phpunit.xml
ubuntu-xenial-16.04-cloudimg-console.log

What am I doing wrong? I would like to see in status all the files that are inside /vendor/Demo/library/BBDD, /vendor/Demo/library/Data and /vendor/Demo/library/File and the file in /vendor/autoload.php

Upvotes: 0

Views: 535

Answers (2)

Samir Aguiar
Samir Aguiar

Reputation: 2559

Although you have excluded those files from the .gitignore pattern, you still need to tell Git to track them by running git add vendor. It will then start showing you the differences in those files.

Upvotes: 1

Raza Mehdi
Raza Mehdi

Reputation: 941

You also need to add !vendor/autoload.php file. Also i would suggest that your create another .gitignore file this time in the vendor folder, and put in the following:

*.*
!autoload.php
!Demo

Upvotes: 1

Related Questions