tags:

views:

95

answers:

4

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.

+1  A: 

This one bugged me for days. The .htaccess file is already under version control and has been modified.

Marcelo Cantos
+2  A: 

It seems that the .htaccess file has already been added to the version control. You need to remove it first, before it can be ignored. This can be done using git rm

Marc
I know, but I don't want to delete the file. I just want to ignore the changes
Fu86
If there is a version of .htaccess in the version control, but you just don't want to commit any changes, .gitignore won't work. There is no option for this as far as I know. Just don't add that file to a commit.
Marc
you can use git rm --cached which will leave the file in the directory standing but remove it from the index
Peter Tillemans
+2  A: 

Ignoring files in git doesn't mean that you won't push them. It means that you won't version control them. If you don't want to push then, I suggest you create a local branch which will contain stuff for the local machine and then merge necessary changes to a branch which you'll push to remote.

I think you've already added your files and are now trying to ignore them.

Noufal Ibrahim
A other way I use now is to stash the local changes and pop the stash back after merging/rebasing.
Fu86
+3  A: 

Since you want to:

  • keep .htaccess in the Git repo (no git rm)
  • have local sensitive data in it

use a filter driver which will:

  • during the checkout phase, complete the .htaccess with private data
  • during the commit phase clean the .htaccess from all sensitive data

alt text

you can then version an encrypted file that your smudge script will:

  • be the only one to decrypt
  • use in order to complete the classic (and pushed/pulled) .htaccess file.

You can version that encrypted sensible data in a special branch you won't push, but even if you did push that file somehow, the damage is limited since only your workstation has the private key needed to decrypt said file.

VonC
+1 for the pretty picture and the filter driver. I was wondering when you'd pitch in this being a version control question and all. :)
Noufal Ibrahim
+1 for automation. I was going to suggest `git update-index --assume-unchanged`, which may still work as a simple solution, but this kind of automation is fantastic.
Rob Wilkerson