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?
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With