Reordering commits

Suppose now that we want to reorder commits. In our example, commit 099c06d should come before commit 23b2c04, so we need to change their order. Once again, we use interactive rebasing to achieve this. So we run

git rebase -i 70ef834

since commit 70ef834 is the parent commit of the oldest of the two commits that we want to reorder.

Reordering commits 1

Now in GitLens we can grab and drag the commits that we want to reorder, and drop them in their final destination on the commit tree. If you are not using GitLens you can move lines around in VS Code with Alt + arrow (up or down as needed).

Reordering commits 2
Reordering commits 3

Since there were no conflicts or actions for us to make, Git took care of everything as soon as we closed the VS Code file. If we check the log now, we'll see that the commit is where we wanted it to be.