Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move one commit to the top of all commits

Tags:

git

I've made a commit, CM, and then applied several patches, P1 and P2. So my history looks like

C1-C2-CM-P1-P2

where C1 and C2 are two previous commits.

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

C1-C2-P1-P2-CM
like image 857
lapots Avatar asked Jan 26 '15 10:01

lapots


2 Answers

If you haven't push your branch yet, you can do an interactive rebase:

git rebase -i C2

You can then reorder your commits as P1-P2-CM, and re-apply them on top of C2.

like image 170
VonC Avatar answered Sep 22 '22 13:09

VonC


You can use rebase -i.

$ git rebase -i HEAD~5

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

like image 42
Simone Carletti Avatar answered Sep 20 '22 13:09

Simone Carletti