Reputation:
I spelled some words wrong in a past commit message and want to fix them.
They were not from the last commit (5 commits ago) so --amend
doesn't work here.
What would be the easiest way to fix this mistake?
Upvotes: 4
Views: 977
Reputation: 255
Identify the commit you want to change with git log --oneline
.
$ git log --oneline
5ebe0d0 foo
66096c8 bar
d83d7a7 *typo*
a9f4c59 baz
...
Then do an interactive rebase onto the parent of that commit (identified with the ^
).
$ git rebase --interactive 'd83d7a7^'
This should fire up the default editor – which, unless you've changed it, is vim.
(This is for those less comfortable with vim.)
Press cw and type the word edit
. Press esc and type :wq
to save and quit the file.
Now all you have to do is git commit --amend
, and you'll be prompted to edit your commit message. Then finish the rebase with git rebase --continue
.
NOTE: if you have any merge history, this will flatten it. If you really don't want this, use the --preserve-merges
option with git rebase
(as well as --interactive
).
Upvotes: 5