Git - Cherry picking with ours/theirs strategy
Asked Answered
H

1

15

I wonder if there is any way of cherry picking with ours/theirs strategy. On other words, I want to cherry pick multiple commits from dev branch into main branch with below commands,

git cherry-pick HASH1 HASH2 HASH3 -n

This command is supposed to take all referred commits and prepare unstaged changes if no conflicts. However, if conflicts, I need to resolve and continue cherry-picking. For all conflicts, my intention is to pick whatever in the dev (which means, --strategy-option = ours).

Is there any way to provide such option while cherry-picking.

Hecklau answered 10/8, 2017 at 4:55 Comment(0)
V
24

The git cherry-pick command does have the --strategy and --strategy-option=<option> options.

They are passed through to the merge strategies.

So, in your case:

git cherry-pick --strategy=ours HASH1 HASH2 HASH3 -n
Venture answered 10/8, 2017 at 5:8 Comment(9)
I tried, this didn't work for me. It always gives hints to apply after manual conflicts resolution. :(Hecklau
@SazzadHissainKhan What git version are you using?Venture
git version 2.11.1, on MacHecklau
OK, strange. Just for testing, would that be the case with Git 2.14.0?Venture
@SazzadHissainKhan it should be working: https://mcmap.net/q/224888/-force-git-to-accept-cherry-pick-39-s-changesVenture
I wonder if it gets disabled by -n (which uses a somewhat different code path). If so, you could get the same effect by running without -n, and then later, squashing.Clipfed
@SazzadHissainKhan Did you get torek's comment? Try without the -nVenture
Its now git cherry-pick --strategyBarbwire
@Barbwire Thank you for the feedback, i Have edited the answer accordingly.Venture

© 2022 - 2024 — McMap. All rights reserved.