Kunok
Kunok

Reputation: 8759

.gitignore didn't ignore files

I have my CakePHP project which has different config content than config on server.

I used this command to create .gitignore file: cd /var/www/html/tmc && touch .gitignore

Then I wrote this into the file:

/app/tmp/*
/app/Config/core.php
/app/Config/database.php
/vendors/*

However when I push, these files are changed again.

What have I done wrong?

Upvotes: 0

Views: 628

Answers (3)

anonymous_user
anonymous_user

Reputation: 9

https://stackoverflow.com/a/37677391/19620781

The response here was phenomenal, but just to simplify...

Make sure you're running inside the root folder of your entire project. For example...

enter image description here

Once that is done, run the following command.

git rm --cached (insert file or directory you want to ignore here)

If you get this error

fatal: not removing (insert file or directory you want to ignore here) recursively without -r

Run this:

git rm -r -f --cached (insert file or directory you want to ignore here)

Upvotes: 0

Raza Shekh
Raza Shekh

Reputation: 24

execute from root directory even if not ignore by .gitignore file step 1 git update-index --assume-unchanged filename

step 2 go to exclude file which is inside .git/info and copy past the filename inside exclude file

e.g. to exclude rootfile/abc.txt file
git update-index --assume-unchanged rootfile/abc.txt and in exclude file which is inside .git/info file rootfile/abc.txt

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520888

Most likely, your files are already being tracked by Git, in which case Git will disregard your .gitignore rules and commit the files anyway. If you want to make Git forget about the files you will have to git rm them from the repository:

git rm --cached app/Config/core.php
git rm --cached app/Config/database.php

and so on for all the files you want to ignore.

After running these commands your working tree should have changes corresponding to the removes you have done. After you commit and push, the files will no longer be tracked.

Upvotes: 3

Related Questions