Shyam
Shyam

Reputation: 2377

Git and Rails: ignore database.yml

I finally made a great step by abandoning SVN for Git and loving it. It must be somewhere, but I can't really find on how to do this, gitosis friendly.

I have my repo 'site' stored on a remote machine. I push my working copy and pull this data on a production machine. One mayor difference though is 'one' file: database.yml, which will never change on the production machine.

Is it possible (and if so, how), when the data is pulled from the repo, to "ignore" only this file? I am doing this manually at this point, but some elegance would be most appreciated.

Thanks.

Upvotes: 8

Views: 8681

Answers (5)

Ali Hassan Mirza
Ali Hassan Mirza

Reputation: 582

If you want to remove your system cache or from your local machine simply run following command.

git rm --cached config/database.yml 

If you want to remove from git then run following commands

git rm config/database.yml
git commit -a -m "Removed database.yml"
git push branch_name

Upvotes: 0

Matthew Crowder
Matthew Crowder

Reputation: 1

Removing the database.yml is not a good idea if the application is designed to be downloaded and installed by other users. If you have unsophisticated users installing your application, the removal of the file is kind of a dick move. Telling git to ignore the file after adding it with default values is the correct way in this case.

Upvotes: 0

ArunKumar Kandasamy
ArunKumar Kandasamy

Reputation: 1026

If "database.yml" got added to your git repo before you specified it in the ignore file, I think you have to remove it:

git rm config/database.yml
git commit -a -m "Removed database.yml"

Then, add database.yml file in your project, will work fine.

Upvotes: 6

Amadan
Amadan

Reputation: 198334

My advice: don't even put it into git. Make a database.yml.skel or something like that, so that a user can model their own database.yml, with that in mind as a sample. However, in my opinion conf files do not belong in version control - exactly for the reason you mention.

Ignoring is very easy: in fact, there are several ways to do it. The correct for this one is .gitignore file; another one is .git/info/excludes. See this answer for details.

So, off the top of my head:

echo database.yml >> config/.gitignore
git add config/.gitignore
git commit

Upvotes: 5

Evgenii
Evgenii

Reputation: 37339

Yes, it is possible.

git update-index --skip-worktree FILENAME

or

git update-index --assume-unchanged FILENAME

where FILENAME would be config/database.yml for your case.

If you use the second command (assume-unchanged), the files will revert after git reset command.

Upvotes: 8

Related Questions