The best way to edit multiple commits is with git rebase.
Using rebase you wouldn't even need to checkout to each commit you want to edit. All you would need to do is
git rebase -i <the oldest commit you want to edit>
The -i
will open a text editor listing all commits up to the commit you passed. So you wold see someting like this:
pick 2e0ed56d Message 1
pick f38dd6ed Message 2
pick 5518e03e Message 3
# Rebase d29d7e11..2283c3c9 onto d29d7e11 (5 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Now all you need to do is replace the pick
in front of each commit you want to amment with e
or edit
save you changes and close the file. You will now be asked to ammend each commit individually.
Now be warned: The way git rebase
works is by deleting your commits and creating copies of them with your changes. So be very careful if you are sharing the repository with other people.
You can use
git push -f
if you want to push your changes to a server and discart the previous versions of thoses commits. Just make sure no one else you are working with has pulled your current branch.