Reputation: 5521
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?
Upvotes: 11
Views: 10260
Reputation: 59963
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
Upvotes: 4
Reputation: 14583
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>
Upvotes: 18