Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore doesn't ignore files

My .gitignore file gets ignored and the files which should be ignored are still visible.

user@host ~/workdir % git status # On branch master # Changed but not updated: #   (use "git add <file>..." to update what will be committed) #   (use "git checkout -- <file>..." to discard changes in working directory) # #       modified:   .htaccess #       modified:   application/controllers/statistics.php # no changes added to commit (use "git add" and/or "git commit -a") user@host ~/workdir % cat .gitignore .htaccess application/config/config.php application/config/database.php user@host ~/workdir % 

The files are in version control, but with sensible changes I dont want to push. git rm ... is not an option because the files should be in version controll (with other settings in the files). I just dont want to push my changes on this files.

like image 786
f00860 Avatar asked Jun 03 '10 10:06

f00860


People also ask

Why is .gitignore not ignoring my files?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them. Igal S.

Why is it that my Gitignore doesn't work?

The Solution To resolve the problem remove from the repository the tracked files contained in the . gitignore file. To achieve this use “git rm” to remove and untrack all the files in the repository, then use “git add” to re-add all the files (the files contained in the .

How do I ignore an already committed file in git?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.


1 Answers

i had same problem: i wanted different .htaccess file per repository then i couldn't because htaccess file had already been added to repository. It's working now, i can change any of the .htaccess file from any version without getting git pushing them. Marc is right when he says "You need to remove it first, before it can be ignored. This can be done using git rm".

i proceeded in this order:

  • backup your .htaccess file somewhere
  • remove .htaccess file using git rm .htaccess
  • commit this change (.htaccess deletion)
  • push it (git push)

this will obviously remove your .htaccess file

  • then edit .gitignore and add /.htaccess
  • commit then push it
  • recreate your .htaccess file by restoring your previous backup

then you're done: whatever changes you make into .htaccess won't be pushed anymore. The hard part is following steps order...

hope this is clear

like image 79
anybug Avatar answered Sep 25 '22 01:09

anybug