29

What strategies do people have for resolving Gemfile.lock conflicts while rebasing in Git?

I am having to do this a lot in a recent project, and not only is it tedious, it's not always clear how to do the merge.

1
  • This problem happened to me because I was confused about which branch I was on. The solution was to slap my forehead and switch back to the correct branch and the Gemfile.lock conflict conflict errors went away. Commented Jun 15, 2016 at 13:15

3 Answers 3

23

you could relock it on every merge, through a merge driver (that I usually use to always keep the local version of a file during a merge).

See "Auto Merge Gemfile.lock" from Will Leinweber:

All you have to do is run bundle lock (obsolete in Rail3) bundle install to get bundler to relock then add that and continue your rebase.

First is your ~/.gitconfig file.
Here we're going to give it a new merge strategy, one that will just relock the gemfile.
Add this to the end:

[merge "gemfilelock"]
  name = relocks the gemfile.lock
  driver = bundle install

Next up, we have to tell git to use our new strategy for Gemfile.lock, and we do that with gitattributes.
You can either put this in project/.git/info/attributes or project/.gitattributes.

Gemfile.lock merge=gemfilelock
2
4

Use git log Gemfile.lock to find the hash of a previous commit. Then run git checkout abcde Gemfile.lock to revert back. Your bundle install command should work after that.

1

You can use this script to automatically set up a git repository to use the mentioned merge resolution strategy: https://gist.github.com/itspriddle/5548930

Alternatively, you can use tpope's hookup to do this (and run database migrations) automatically after git pulls: https://github.com/tpope/hookup

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.