From what I know, by default the cherry-pick
command takes a commit and places it on top of the current branch.
Is it possible to cherry-pick
a commit in Git and place it below the current commit?
Cherry picking in Git means to choose a commit from one branch and apply it onto another. This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch. Make sure you are on the branch you want to apply the commit to.
Here's another approach. Let's say your history looks like this:
A - B - D master, HEAD
\
C other
and you want to cherry pick commit C
before HEAD
so that the resulting history becomes:
A - B - C' - D' master, HEAD
\
C other
Then you can do:
git checkout HEAD^
to move HEAD
to commit B
git cherry-pick other master
to apply commits C
and D
on top of B
git branch -f master HEAD
to make master
point to the same commit as HEAD
git checkout master
to move HEAD
to master
You can always perform a rebase
after the cherry-pick. So it would look something like that:
git cherry-pick <hash>
git rebase HEAD~2 -i
Swap the commit orders in the rebase window.
Second Option
In case you want to solve conflicts only once, as you stated. You can take the long way. Remove the current commit, cherry pick the other one, and then cherry-pick the latest commit.
git log --oneline -1
<write_down_this_hash> description
git reset --hard HEAD~1
git cherry-pick <hash to cherry pick>
git cherry-pick <write_down_this_hash>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With