valerij vasilcenko
valerij vasilcenko

Reputation: 258

git ignore whole folder excluding one file

Hey this does not work for me:

vendor/*
!vendor/predis/
vendor/predis/*
!vendor/predis/predis
vendor/predis/predis/*
!vendor/predis/predis/lib
vendor/predis/predis/lib/*
!vendor/predis/predis/lib/Predis
vendor/predis/predis/lib/Predis/*
!vendor/predis/predis/lib/Predis/Profile
vendor/predis/predis/lib/Predis/Profile/*
!vendor/predis/predis/lib/Predis/Profile/ServerVersion24.php

Where did I make a mistake?

Upvotes: 2

Views: 182

Answers (2)

Piotr Zierhoffer
Piotr Zierhoffer

Reputation: 5151

What is your actual state of the repository?

I believe that what you want to have is just:

vendor/*

Prior to creating .gitignore file, just git add vendor/predis/predis/lib/Predis/Profile/ServerVersion24.php. It will now be tracked.

After you create .gitignore file (or add the mentioned line to it) all untracked files in vendor directory will be ignored.

[EDIT] (Correction after helpful comments, thanks!)

Please keep in mind that you cannot ignore a file that is already tracked. If you want to do that, you need execute command git update-index --assume-unchanged against the files you want to ignore - but this change will be local to your repository, it will not be shared. For more details see How to ignore files only locally in git?.

Upvotes: 1

leo108
leo108

Reputation: 817

create .gitignore with

vendor/*

then git add -f vendor/predis/predis/lib/Predis/Profile/ServerVersion24.php

the -f option will ignore the rules in .gitignore, so the file will be tracked

Upvotes: 0

Related Questions