• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Computing / Git Interactive Rebase Order is Wrong
Screenshot of Git Log and Git Rebase Interactive showing in one case the newest commit is at the top and in the other case the newest commit is at the bottom.

Git Interactive Rebase Order is Wrong

Last updated on January 14, 2019 by Sal Ferrarello

The interactive rebase feature of Git is one of my favorites. I love being able to squash multiple commits into one commit or re-order my commits for clarity. My one complaint is the Git interactive rebase order is wrong (at least for the way my brain works).

Commits as a Stack

My mental model for commits is a stack, where items can be pushed on (or popped off) the top. git log supports this model with the latest commits appearing on the top. On the other hand, by default git rebase --interactive is reversed with the latest commits on the bottom.

Screenshot of Git Log and Git Rebase Interactive showing in one case the newest commit is at the top and in the other case the newest commit is at the bottom.

Not the Only One

While I understand when something is appended to a file it goes on the end of the file and this mental model matches how commits are displayed with Git interactive rebase, that knowledge does not help change the fact that I need to perform a mental shift when I switch between git log and git rebase --interactive

I’m not the only one who feels it would be more intuitive if the order of commits in git interactive rebase were reversed (post from May 2011).

My Solution

Since I use Vim as my editor when working with Git, I wrote a Vim plugin to reverse the order of the commits in an interactive git rebase.

With the plugin

Note the interactive rebase window on the right now has the most recent commits on the top.

Screenshot of git rebase --interactive with the order of the commits reversed.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Computing, Dev Tips, Recommendations, Solution Tagged With: Git, rebase

Reader Interactions

Comments

  1. yunslee says

    July 16, 2022 at 3:11 am

    I agree with you, this is very confusing me!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in