force git to accept cherry-pick's changes
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).
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.
- I grab the commit hash of that commit.
- Then checkout on to the branch I want to have such commit.
- Then run the command above, e.g.
git cherry-pick -X theirs 5cf3412
If you are already in conflict state, simply do
# add only conflicting files heregit checkout --theirs path/to/filegit add path/to/filegit cherry-pick --continue