Git cherry pick a fix and place it below

From what I know, by default, the cherry-pick command accepts a commit and places it on top of the current branch. Is it possible to perform a cherry-pick commit in Git and place it below the current commit?

+5
source share
2 answers

You can always rebase after a set of cherries. So it will look something like this:

 git cherry-pick <hash> git rebase HEAD~2 -i 

Change the commit orders in the forwarding window.

Second option

If you want to resolve conflicts only once, as you have stated. You can go a long way. Delete the current commit, select another cherry, and then select the last commit cherry.

 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> 
+8
source

Here is another approach. Let's say your story looks like this:

 A - B - D master, HEAD \ C other 

and you want to select cherry commit C before HEAD so that the resulting story becomes the following:

 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 apply commits C and D on top of B
  • git branch -f master HEAD , to make master , point to the same message as HEAD
  • git checkout master to move HEAD to master
+2
source

Source: https://habr.com/ru/post/1245088/


All Articles