开发者

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 'sit开发者_如何学编程e' 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.


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.


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.


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


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜