Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubles with git and Gemfile.lock

I keep running into the following error with my Gemfile.lock whenever I want to do a git pull or checkout a new branch.

error: Your local changes to the following files would be overwritten by merge:     Gemfile.lock Please, commit your changes or stash them before you can merge. Aborting 

The problem is that I can't figure out how to fix it.

  • Stashing the file doesn't work -- the local changes just stay there for some reason.
  • I've also tried running git checkout -- Gemfile.lock to discard the changes, but that doesn't work either -- the local changes just stay there.
  • I've also tried creating a new branch and committing the Gemfile.lock changes just to that branch... but that doesn't work either. The changes remain!

What do I need to do? I've gone so far as to just clone a new git repo, but soon enough, all this starts happening again.

like image 650
grautur Avatar asked Jun 14 '15 21:06

grautur


People also ask

Should I add Gemfile lock to Git?

You should always include your Gemfile. lock if you are writing an application. The community seems to (largely) agree that you should include it in any Gems you create as well.

What creates Gemfile lock?

The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

Is Gemfile lock automatically generated?

Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.

How do I remove gem from Gemfile lock?

You can run just bundle or bundle install to install gems based on your Gemfile. That will remove the instance of mygem from your Gemfile. lock file.


Video Answer


1 Answers

This happened to me and git reset --hard HEAD from the accepted answer didn't help. However, running spring stop did the trick. I suspect spring is rewriting the file whenever it is modified to ensure that it is in sync with the code running via spring.

like image 181
Tristan Havelick Avatar answered Sep 21 '22 08:09

Tristan Havelick