I just inherited an existing codebase that has multiple configuration files in it. These configuration files are all generic, meant to be edited and customized for each machine they are downloaded to. Git is (obviously) telling me that they have been edited and is always showing them under "changes not staged for commit" every time I do a git status
. How can I ignore these files under git? Adding them to .gitignore doesn't work because they are already being tracked by git. I don't want to commit anything to the repo, but at the same time I want to tell git not to track these files anymore on my local machine. Is there a way of doing this that I'm not aware of? I know I can git stash
them and they won't be shown anymore, but I feel that is not really what it was meant for... Am I wrong?
Not sure if this changes anything, but I am using git-svn on my local machine to interact with the SVN server.
My suggestion would be:
*.properties
to*.properties.example
*.properties.example
to repository*.properties
from repository*.properties
to.gitignore
I do something like David Schwartz suggests, which is to create something like shell/template configurations like
database.yml.template
and then copy that file and configure it for my environment asdatabase.yml
. Then I can.gitignore
those new files.If you want to do it without modifying how the files exist in repo, then:
Will make git ignore changes to that file, but you have to be conscious of doing it.
More information here: http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html
To ignore files already tracked by git I have a git alias set up (which actually just does what birryree suggests, but more conveniently). Add this to your .gitconfig:
Then you can do
git ignore foo
,git unignore foo
, orgit ignored
to list the ignored files.You want to use the
skip-worktree
bit, not theassume-unchanged
bit.See this question for why this is preferable to
assume-unchanged
, and this webpage for some of the ramifications.Basically,
skip-worktree
tries very hard to keep your changes to the file, butassume-unchanged
might lose them when you perform some operations.Don't store configuration files on the repository. You can store example versions of those files or 'generic' versions of them in the repository, but do it under another name.
If there are several of them and they live in their own directory, create a separate directory to hold the generic versions in the repository. If there are only one or two of them and they don't have their own directory, use file names. You can add something like
-default
or-example
to the versions stored in the repository.