Search code examples
gitgit-mergegit-cherry-pick

Merging specific commits without cherry-pick?


So, I've been using git cherry-pick for this but it's getting cumbersome and I wanted to know if there's a simpler way (or another approach).

Say I have 3 branches: master (stable, candidate for production), develop (working branch) and production.

Now, beside the stable milestones, production has some production-specific settings. Things I don't want to change every time I merge into it. I can't simply merge develop into master and then master into production, nor develop straight into production, because this would create a conflict with the production settings.

So far issuing git cherry-pick commitA^..commitB in production has worked, but I don't want to keep doing this every time.

Am I missing something obvious? Is there a simpler way to merge just the commits of a single branch?


Solution

  • It sounds to me like you should look at Git Attributes. Make a .gitattributes file containing rows like:

    settingsfile merge=ours
    

    This will stop the settingsfile from being overwritten by merges. Instead of conflicting, this will silently resolve the merge by accepting the current state of the file.

    For more details, see this answer about how to create a custom merge driver