Change a git commit from the past (not the most recent one)

# Figure out which commit you want to edit by getting its SHA.
git log

# Start an interactive rebase ($SHA = your commit's SHA and the ^ is important!).
git rebase --interactive $SHA^

# [Change 'pick' to 'edit' for your commit and save the buffer]

# [Add your changes with git add -p, etc.]

# Change the commit and optionally add --no-edit if you want to keep the existing message.
git commit --amend

# Finalize and apply the rebase.
git rebase --continue

# Or cancel the rebase and go back to what it was like before you started rebasing.
git rebase --abort
From Nick Janetakis – Change a Git Commit in the Past with Amend and Rebase Interactive (
This entry was posted in Version control and tagged , , by swk. Bookmark the permalink.

About swk

I am a software developr, data scientist, computational linguist, teacher of computer science and above all a huge fan of LaTeX. I use LaTeX for everything, including things you never wanted to do with LaTeX. My latest love is lilypond, aka LaTeX for music. I'll post at irregular intervals about cool stuff, stupid hacks and annoying settings I want to remember for the future.