Open Source

Mastering Targeted History Rewrites with Git 2.54's New `git history` Command

2026-05-01 03:43:10

Introduction

Git 2.54 brings a fresh experimental command, git history, designed for making focused, non-interactive changes to your repository's past. Unlike the full-featured but sometimes overwhelming git rebase -i, git history lets you fix a typo in an old commit message or split a single commit into two without touching your working tree or index. This guide will walk you through everything you need to get started with git history reword and git history split—the two operations currently supported.

Mastering Targeted History Rewrites with Git 2.54's New `git history` Command
Source: github.blog

What You Need

Step-by-Step Guide

Step 1: Verify Your Git Version

First, confirm you have Git 2.54 or newer installed. Open your terminal and run:

git --version

If the output shows a version lower than 2.54, update Git using your system's package manager or download the latest from git-scm.com.

Step 2: Understand the git history Command

The command is built on the git replay machinery, which has been extracted into a library for this purpose. It is not a replacement for interactive rebase; rather, it fills a gap for simple, targeted edits that don’t require the full rebase workflow. Key points:

Step 3: Rewriting a Commit Message with git history reword

Suppose you need to fix a typo in a commit from three steps back (e.g., commit abc123). With git rebase -i you’d mark that commit for editing, then amend and continue. With git history reword, it’s much simpler:

  1. Run the command with the target commit reference:
    git history reword abc123
  2. Your default text editor will open with the current commit message. Make your changes and save.
  3. Git automatically rewrites the commit and updates all descendant branches (if any) to point to the new version. No need to touch your working directory or index.

This operation works even in a bare repository, making it ideal for server-side scripts or CI pipelines.

Step 4: Splitting a Commit into Two with git history split

Sometimes a single commit contains unrelated changes that should be separated. The split subcommand lets you interactively choose which hunks (diff chunks) to move into a new parent commit. Here’s how:

  1. Identify the commit you want to split (e.g., HEAD) and run:
    git history split HEAD
  2. Git will present each hunk from the commit’s diff, one by one, asking whether to include it in the new parent commit. The prompt looks like:
    (1/1) Stage addition [y,n,q,a,d,p,?]?
  3. Answer y to move the hunk into a new commit that will become the parent of the original commit. Answer n to keep it in the original commit.
  4. After you’ve made selections, Git creates a new commit containing the chosen hunks. The original commit retains the remaining hunks. All branches that descend from the original commit are automatically rewritten to point to the updated history (new parent + original commit).

Note that the interface is familiar if you’ve ever used git add -p (interactive staging). The same options apply: y for yes, n for no, q to quit, a for all, d for none, etc.

Mastering Targeted History Rewrites with Git 2.54's New `git history` Command
Source: github.blog

Step 5: Verify the Rewritten History

After using either reword or split, check your history with:

git log --oneline --graph

For a split, you’ll see two commits in place of one. For a reword, the commit message will reflect your changes. The command updates all branch references, so git log --all will show the new structure.

Step 6: Recover If Something Goes Wrong

Because git history rewrites history, it’s wise to have a backup. If you haven’t pushed the changes yet, use git reflog to find the original state and reset:

git reflog
# find the commit before the rewrite
git reset --hard HEAD@{1}

If you’ve already pushed, coordinate with your team and force-push with care.

Tips and Best Practices

With git history, Git 2.54 offers a more surgical approach to history rewriting. Start using it for quick fixes and watch your productivity improve.

Explore

Mastering View Transitions: A Q&A Guide Exploring Why are top university websites serving porn? It comes down to shod... How to Install and Explore Fedora KDE Plasma Desktop 44 How Ann Arbor's Solar + Battery Pilot Could Slash Energy Bills for 150 Homes Tesla Semi Port Pilot: MDB Transportation's Three-Week Test in Southern California