I know two methods to change a commit message in git.
The first is git amend
, which only works for the latest commit. Since I want to be able to change older commit messages directly, this is not what I am looking for.
The second is an interactive rebase as described in this answer for example, which can also change commit messages of older commits. The procedure is to use
git rebase -i HEAD~n
where I have to manually count how large is n
for my specific case, then scroll through a list of all those commits and change the one commit from pick
to reword
, then finally type the new commit message and force push.
Honestly, while this works, it is insanely complicated and tedious to do this. So my questions is, is there an easier to use option (perhaps in form of an alias), where this procedure is automatically performed in one step?
Ideally, I would like to have a command like:
git reword <hash> -m "New commit message"
and after that just force push. Is this possible?
Edit: I want to get rid of the interactivity, because I want to programmatically automatize some git commands from my program. Having to interact manually with git during that process kind of defeats the purpose of such an automation.