可以将Gemfile和Gemfile.lock添加到git

时间:2015-10-31 18:16:04

标签: ruby-on-rails git heroku

我正在尝试将我的应用部署到Heroku。 我删除了'sqlite3'gem并将以下部分添加到我的Gemfile中:

gem 'sqlite3', group: :development

group :production do
    gem 'pg'
    gem 'rails_12factor'
end

之后,我运行了bundle install来更新它。但是,当我尝试git add时,它说:

error: insufficient permission for adding an object to repository database.git/objects
error: Gemfile.lock: failed to insert into database
error: unable to index file Gemfile.lock
fatal: updating files failed

如果我删除了我在Gemfile中添加的代码,一切正常! 我正在运行OSX 10.11.1,Rails 4.2.4,ruby 2.2.1p85和git 2.4.9(Apple Git-60)。

2 个答案:

答案 0 :(得分:1)

The issue is probably because your config/database.yml needs to be configured to use postgresql instead of sqlite.

I highly suggest using postgres for both production AND development by removing the gem 'sqlite3', group: :development from your gemfile and just add gem 'pg' outside of the production group (so it applies to all environments: dev, prod, and test).

Then in your database.yml, in the default: &default section, change adapter to:

  adapter: postgresql

Or if you want to continue using sqlite in dev, just change the production: section in your database.yml to the following:

production:
  adapter: postgresql
  encoding: unicode
  pool: 5

You might need to change the database: value to something like:

  database: your_app_name_production

where "your_app_name" is the name of your app.

NOTE: Be sure to keep the spacing exact as YAML files are whitespace sensitive.

Hope that helps.

答案 1 :(得分:1)

或者你的Gemfile.lock可能有问题。

您应该能够安全地删除该文件(首先制作备份副本,以防万一)。使用git rm Gemfile.lock。 Gemfile.lock只是根据您第一次捆绑安装它们的时间点的最新版本跟踪项目中安装的所有gem的所有版本。

然后当你运行bundle install时,它会自动生成一个新的。

然后再次执行git add -A(最好使用git add *)。