lapots
lapots

Reputation: 13415

move one commit to the top of all commits

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

Upvotes: 8

Views: 8740

Answers (3)

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72865

Do a git rebase -i C1 and then in the editor that pops up, reorder the commits, save and quit. If there are no conflicts or things, it'll reorder it.

Upvotes: 2

VonC
VonC

Reputation: 1329322

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.

Upvotes: 18

Simone Carletti
Simone Carletti

Reputation: 176552

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.

Upvotes: 9

Related Questions