Git 2.54: Introducing 'git history' for Painless Commit Rewrites

From Bioinfa, the free encyclopedia of technology

Git 2.54 has arrived, packing contributions from over 137 developers, 66 of whom are first-timers. This release focuses on making history rewriting simpler for everyday tasks. The star of the show is an experimental command called git history, designed to handle common operations like fixing a commit message or splitting a commit—without the overhead of a full interactive rebase. Let's dive into the details.

What is the new 'git history' command and why was it created?

Git has long offered powerful tools for rewriting history, with git rebase -i being the most famous. But interactive rebase is a heavy process: it works on a range of commits, updates your working tree and index, and can leave you resolving conflicts. For simple jobs like correcting a typo in a commit message from three commits back, that’s overkill. git history is a new experimental command tailored for these lighter tasks. It currently supports two operations: reword (edit a commit message) and split (break one commit into two). The command operates without touching your working tree or index, and it can even run in a bare repository. It's built on the core machinery of git replay, which was itself extracted into a library as part of this work.

Git 2.54: Introducing 'git history' for Painless Commit Rewrites
Source: github.blog

How does 'git history reword' work?

Using git history reword <commit> opens your editor with the commit’s current message. After you make changes, the command rewrites the commit in place and updates any descendant branches. Unlike an interactive rebase, this operation never touches your working tree or index. It also works in bare repositories, making it ideal for server-side or automated workflows. This targeted approach avoids the complexity of managing a rebase todo list and reduces the risk of introduction of conflicts from unrelated changes. It’s the perfect tool for quickly fixing a typo in an older commit message.

How does 'git history split' work?

git history split <commit> lets you interactively divide a commit into two. The interface will be familiar if you’ve ever used git add -p. It presents each hunk of the commit’s diff and asks you whether to include it in the new first commit. For example, running git history split HEAD shows diffs like a new file addition and waits for your decision (y/n/q/a/d etc.). After you select hunks, Git creates a new commit containing those changes. That new commit becomes the parent of the original commit, which retains the hunks you did not select. Git then rewrites any descendant branches to point at the updated history. This makes splitting a commit that contains unrelated changes straightforward and controlled.

What are the intentional limitations of 'git history'?

The designers of git history deliberately kept it simple. It does not support histories that contain merge commits—if your branch has merges, the command will refuse to run. Additionally, it will refuse to perform any operation that would result in a merge conflict. This means you cannot use it for open-ended rewrites that might require conflict resolution. By design, git history is meant for targeted, non-interactive rewrites of linear history. For more complex needs, such as reordering commits or editing across merges, the traditional interactive rebase remains the tool of choice.

Git 2.54: Introducing 'git history' for Painless Commit Rewrites
Source: github.blog

How does 'git history' differ from interactive rebase?

Interactive rebase (git rebase -i) is a Swiss Army knife for history manipulation. It can reorder, squash, edit, drop, and split commits—all while replaying the entire commit range and updating your working tree. This flexibility comes with complexity: you must set up a todo list, mark commits for editing, and handle potential conflicts. git history strips away that complexity. It operates on a single commit at a time, never touches your working tree or index, and rejects any operation that might cause a conflict. If your only goal is to rewrite a commit message or split one commit, git history is faster, safer, and simpler. For everything else, rebase remains the go-to.

What else is new in Git 2.54 beyond 'git history'?

Git 2.54 includes features and fixes from over 137 contributors, 66 of them new. While the git history command is the headline feature, the release also contains numerous improvements under the hood. Notably, the core machinery of git replay was refactored into a library, which git history now uses. This library extraction paves the way for future tools and scripts that need history rewriting capabilities without invoking a full interactive rebase. Other changes include better performance in some operations and typical bug fixes. For a complete list, refer to the official Git release notes.

Is 'git history' ready for production use?

No—git history is marked as an experimental command in Git 2.54. The Git project advises caution when using experimental features, especially on important repositories. It is recommended to test the command on a clone or backup first. The command’s behavior, options, and even its name might change in future releases. However, for simple, linear histories where you need to quickly reword or split a commit, it already works reliably. If you rely on scripted workflows, be aware that the command’s interface is not yet stable. Expect it to evolve based on community feedback.