Changing a Super Old Git Commit History

Malina Tran
Jan 20, 2017 · 2 min read
It used to be so simple.

I’d like to share a dilemma — and a strange solution.

Over 50+ commits ago, I had a “WIP” commit message that I never changed. The most straightforward solution it seems would be to get the SHA of that commit and run git rebase -i <SHA>.

Reword it? Not a problem.

Except.

Merge conflicts galore. The first few times, it was not a problem. I would fix the conflicts, add them, and git rebase --continue.

Until.

It kept escalating.

It wasn’t even a linear process, which made it even more confusing. It was unclear which version I should use most of the time. Plus, why am I even doing this? I’ve resolved these issues in the past. Why is changing the name of a commit message having these side effects?

While I cannot say that I have a resolution, I did find this solution (god bless Stack Overflow). I adapted the steps and did the following:

  • Went into/usr/local/bin (this could’ve been any usr directory)
  • Created a file called git-reword-commit (this could’ve been called anything so long as it starts with git). In that file, I added the following, based on the SO post (truthfully, I still need to decipher it):
#! /bin/bash
REV=$1
MESSAGE=$2
FILTER="test $(echo '$GIT_COMMIT') = $(git rev-parse $REV) && echo $MESSAGE || cat"
git filter-branch --msg-filter "$FILTER" -- --all
  • The SO post doesn’t say this, but you have to make sure the file is executable. Run chmod +x git-reword-commit
  • Returned to my repository and ran git reword-commit <SHA> "<MESSAGE"
  • git push -f

It 👏🏽 finally 👏🏽 worked 👏🏽 ! 🙌🏽

Tech and the City

Hacking it in my hometown of Los Angeles.

Tech and the City

Hacking it in my hometown of Los Angeles. From urban planner to software developer. From Brooklyn to Downtown LA. Getting real nerdy with it.

Malina Tran

Written by

I design and build things for the web through code. Born & based in LA. malinatran.com

Tech and the City

Hacking it in my hometown of Los Angeles. From urban planner to software developer. From Brooklyn to Downtown LA. Getting real nerdy with it.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store