How to change the message of an old (local) commit?
This question already has an answer here:
How to modify existing, unpushed commits?
3 Solutions collect form web for “How to change the message of an old (local) commit?”
Interactive rebase is frequently the easiest way:
git rebase -i 637bd5ac^
This will open up your editor with each commit since the commit mentioned on a line. For each commit, you can choose how you want to modify it; pick (keep it as is), edit, reword (edit just the commit message), squash (combine that commit with the preceding one into one commit and one commit message), or fixup (like squash but ignore the commit message for the second). You can also reorder or delete commits while doing this.
For your problem, you would want to choose “reword” for the commit in question, then you’ll have an opportunity to edit the message.
git commit -amend can only change the last commit. you should use git rebase -i to select and edit your commit in your commit history.
I want to change the commit message of Make sidenav a component.
I thought of using
git commit -ammendbut I think it can only be used to change the message of the last commit?
git commit -ammend
This will only update your
HEAD which is the latest commit message.
If you wish to update other messages in the chain you have several options:
Interactive rebase =
git rebase -i HEAD~X
Find the commit you want, change pick to
edit), and save and close the file.
Now when git stop on the desired commit use
git commit --amend to make your changes.
Few options here as well. What
git filter-branch does its looping over the set of commits and update them in the way you tell it to.
for example you can use this line to update the desired string:
git filter-branch -f --msg-filter 'sed "s/...//g"' -- --all
Or this script as well (this one modify the commiter data)
# Loop over all the commits and use the --commit-filter # to change only the email addresses git filter-branch --commit-filter ' # check to see if the committer (email is the desired one) if [ "$GIT_COMMITTER_EMAIL" = "<Old Email>" ]; then # Set the new desired name GIT_COMMITTER_NAME="<New Name>"; GIT_AUTHOR_NAME="<New Name>"; # Set the new desired email GIT_COMMITTER_EMAIL="<New Email>"; GIT_AUTHOR_EMAIL="<New Email>"; # (re) commit with the updated information git commit-tree "$@"; else # No need to update so commit as is git commit-tree "$@"; fi' HEAD