Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force git to accept cherry-pick's changes

I did cherry-pick from a gerrit review in my branch. In gerrit code review, I have two patch sets and I cherry-picked patch one before, so now I want to do the second patch set, but there are conflicts, how can I force git to accept all changes? Thanks!

like image 896
Jiang Avatar asked Jan 10 '14 18:01

Jiang


People also ask

How do I undo a failed cherry pick changes git?

Try also with '--quit' option, which allows you to abort the current operation and further clear the sequencer state. --quit Forget about the current operation in progress. Can be used to clear the sequencer state after a failed cherry-pick or revert. --abort Cancel the operation and return to the pre-sequence state.

How do you fix cherry pick conflict?

One possible way to avoid these cherry-pick conflicts is by doing the cherry-picking in the order of oldest commit to latest commit, i.e. based on commit date.


2 Answers

You can tell it to always prefer the changes of the commit you are cherry-picking:

git cherry-pick commitish --strategy-option theirs 

commitish can be a SHA-1 hash of a commit, or a branch-name for the lastest commit of that branch, branch-name~1 for the commit before that etc.

If you want to do the reverse, use:

git cherry-pick commitish --strategy-option ours 

The shorthand for --strategy-option is -X (uppercased X).

PS: What is the commit-ish, tree-ish?

like image 60
CodeManX Avatar answered Sep 28 '22 08:09

CodeManX


git cherry-pick -X theirs <commit-hash-you-want-to-force-cherry-pick-from>

My usual workflow is as follows:

Assuming I'm on the master and I have just made a commit.

  1. I grab the commit hash of that commit.
  2. Then checkout on to the branch I want to have such commit.
  3. Then run the command above, e.g. git cherry-pick -X theirs 5cf3412
like image 25
tallamjr Avatar answered Sep 28 '22 09:09

tallamjr