How to reword a Git commit by its SHA1 hash?
git, git-commit, git-rebase
Solution
You can checkout the commit in question, amend its message and rebase back to your branch manually:
$ git checkout FIRST_COMMIT_SHA
$ git commit --amend
$ git rebase HEAD THE_BRANCH_YOU_CAME_FROM
This git alias will automate this process:
reword = "!f() { branch=`git symbolic-ref --short HEAD`; git checkout $1; git commit --amend; git checkout $branch; }; f"
To add it to your `~/.gitconfig`:
$ git config alias.reword "!f() { branch=`git symbolic-ref --short HEAD`; git checkout $1; git commit --amend; git checkout $branch; }; f"
Then use like this:
$ git reword SHA1_OF_THE_COMMIT_TO_BE_REWORDED
Credits:
- Answer with the original idea
- Q&A on getting git's current branch
Problem
I have created a commit with a commit message that I want to modify. I have not published the commit, yet, so I can rewrite history safely. I can find using git log, so I know its sha1 hash. How can I quickly edit the commit?