Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Cherry picking with ours/theirs strategy

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.

like image 220
Sazzad Hissain Khan Avatar asked Aug 10 '17 04:08

Sazzad Hissain Khan


People also ask

How do you resolve a conflict with a cherry pick?

Points to remember git cherry-pick <commit-hash> to cherry-pick a commit from another branch. git cherry-pick -n <commit-hash> to cherry-pick the commit but it won't commit the changes. It will only stage all the changes. git cherry-pick —continue or git cherry-pick —abort when you face conflicts while cherry-picking.

How do you resolve conflict with theirs?

In order to resolve the conflict use TortoiseGit → Resolve... and then right click on the conflicted file and choose one of Resolved (the current version of the file which is in the working tree will be used), Resolve conflict using 'mine' (the version of the file of your HEAD will be used), and Resolve conflict using ...

What is the best git merge strategy?

The most commonly used strategies are Fast Forward Merge and Recursive Merge. In this most commonly used merge strategy, history is just one straight line. When you create a branch, make some commits in that branch, the time you're ready to merge, there is no new merge on the master.

What is theirs and ours in git?

The 'ours' in Git is referring to the original working branch which has authoritative/canonical part of git history. The 'theirs' refers to the version that holds the work in order to be rebased (changes to be replayed onto the current branch).


1 Answers

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-option=ours HASH1 HASH2 HASH3 -n
like image 165
VonC Avatar answered Oct 13 '22 11:10

VonC