Search code examples
ruby-on-rails-3gitbundlerconflictrebase

Conflicts in Gemfile.lock while rebasing


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.


Solution

  • 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