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.

dangerousdave
  • 6,331
  • 8
  • 45
  • 62
  • 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. – Eric Leschinski Jun 15 '16 at 13:15

3 Answers3

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • according to bundle, bundle lock is obsolete. http://stackoverflow.com/questions/4410116/when-we-need-use-bundlelock-and-unlock-on-rails3 is there an updated solution to this??? – rickypai Jan 13 '13 at 22:57
  • @rickypai yes, I have updated the answer, following http://bitfission.com/blog/2010/07/auto-merge-gemfile-lock.html#comment-100076083: `bundle install` is the new lock. – VonC Jan 14 '13 at 07:42
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.

Ryan Buckley
  • 123
  • 1
  • 3
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

indirect
  • 3,470
  • 2
  • 25
  • 13