0

Say I have following git history:

commit C # Most recent one 
commit B
commit A # First one

And I want to rearrange the C commit to be the second one making the B commit the first as follow:

commit B # Being now the latest
commit C # Previously the latest, now second in history
commit A # Still the first

Btw I've found this question to be a possible duplicate, but the question is too complicated for my simple use case as I don't mess commits with branches.

jirislav
  • 340
  • 6
  • 16
  • 1
    Why would you want to do this? – Makoto Mar 29 '18 at 19:14
  • It is quite regular to split your code modifications into separate commits so that the changes are more comprehensible. And I've made some changes that would make much more sense during the code review in case of rearranged commits instead of the current sequence, when the reviewer follows up my proposed changes - commit by commit. – jirislav Mar 30 '18 at 10:03

1 Answers1

3

You can use rebase

git rebase -i A

Then change the order from

commit C
commit B

change to

commit B
commit C

and continue the rebase.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218