Git and Rails: ignore database.yml
Asked Answered
F

5

8

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.

Fredel answered 18/5, 2010 at 12:0 Comment(0)
V
5

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
Vallee answered 18/5, 2010 at 12:40 Comment(6)
or put config/database.yml in .gitignoreExorcism
If anyone uses the code above and they already have a .gitignore, it'll be gone. I recommend using >> and only using > if the first fails. (Depending how your shell is configured, >> may work in both cases where you have the file and you don't.) So the first line would be echo database.yml >> config/.gitignore instead.Ridenhour
Also, this does you no good if the database.yml is already in the repo. See Evgeny's answer for details on how to handle that situation. (I haven't tested his approach: it's a bit different from mine, but you're basically removing the file from the repo so the .gitignore can be applied.)Ridenhour
@iconoclast: I never said anything about what to do if it's already in the repo, just that it shouldn't be. Evgeny's code is definitely not removing code from the repo, and has nothing to do with .gitignore (except slight similarity in functionality). And I assume everyone who uses git can also tell the difference between > and >>, and modify to suit the occasion (or use an editor instead to do the same thing).Vallee
Yes, but it seems pretty clear that it is already in the repo, since he asks how to ignore it when he PULLS, not ignore it from the working directory. (Remember he's new to Git so you can't count on his terminology being standard.) He seems to want the file in the repo to not overwrite his production file.Ridenhour
If the file is already in Git, use git rm --cached config/database.yml to remove it from Git while keeping it local on disk.Malaria
K
8

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.

Keneth answered 1/2, 2012 at 7:45 Comment(0)
P
6

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.

Portie answered 24/2, 2014 at 7:25 Comment(1)
You will most likely want to keep it local on your disk: git rm --cached config/database.ymlMalaria
V
5

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
Vallee answered 18/5, 2010 at 12:40 Comment(6)
or put config/database.yml in .gitignoreExorcism
If anyone uses the code above and they already have a .gitignore, it'll be gone. I recommend using >> and only using > if the first fails. (Depending how your shell is configured, >> may work in both cases where you have the file and you don't.) So the first line would be echo database.yml >> config/.gitignore instead.Ridenhour
Also, this does you no good if the database.yml is already in the repo. See Evgeny's answer for details on how to handle that situation. (I haven't tested his approach: it's a bit different from mine, but you're basically removing the file from the repo so the .gitignore can be applied.)Ridenhour
@iconoclast: I never said anything about what to do if it's already in the repo, just that it shouldn't be. Evgeny's code is definitely not removing code from the repo, and has nothing to do with .gitignore (except slight similarity in functionality). And I assume everyone who uses git can also tell the difference between > and >>, and modify to suit the occasion (or use an editor instead to do the same thing).Vallee
Yes, but it seems pretty clear that it is already in the repo, since he asks how to ignore it when he PULLS, not ignore it from the working directory. (Remember he's new to Git so you can't count on his terminology being standard.) He seems to want the file in the repo to not overwrite his production file.Ridenhour
If the file is already in Git, use git rm --cached config/database.yml to remove it from Git while keeping it local on disk.Malaria
E
0

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.

Endocranium answered 5/5, 2016 at 1:47 Comment(0)
R
0

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
Recife answered 13/8, 2018 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.