Move one commit to the top of all commits

I did commit, CM , and then applied some patches, P1 and P2 . So my story looks like

 C1-C2-CM-P1-P2 

where C1 and C2 are the two previous fixations.

The problem is that I forgot to create a patch for my commit. How to move my CM commit to the beginning of commits? The story should look like

 C1-C2-P1-P2-CM 
+6
source share
3 answers

If you have not clicked your branch yet, you can do an interactive reboot:

 git rebase -i C2 

Then you can reorder your commits as P1-P2-CM and reapply them on top of C2 .

+8
source

You can use rebase -i .

 $ git rebase -i HEAD~5 

It will open your text editor with the last 5 commits. Replace the commits in the order you want, then save and close.

+5
source

Do git rebase -i C1 , and then in the editor that appears, change the commit order, save and close. If there are no conflicts or things, this will change the order.

+2
source

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


All Articles