Occasionally I will drop into troubleshooting mode and commit/push a number of small but separate commits with a comment like, "Troubleshooting the <something> during deployment to Heroku." I would like to use the same comment for each commit without having to retype it. Is this possible?
If you've already created a fresh commit, you'll want to use git rebase -i to squash your commit on top of the old one. After you've made this change locally, and verified your commit looks the way you want it to, you'll have to git push --force to overwrite history on the Github remote.
To change the most recent commit message, use the git commit --amend command. To change older or multiple commit messages, use git rebase -i HEAD~N .
To make it work for multiple commits, just create a temporary commit with your newest changes and then use an interactive rebase to squash the previous commit (containing the good commit message) with the new temporary one, keeping the commit message of the old commit.
From the git-commit(1) command documentation,
-C <commit> --reuse-message=<commit> Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit. -c <commit> --reedit-message=<commit> Like -C, but with -c the editor is invoked, so that the user can further edit the commit message.
It's then possible using,
git commit --reuse-message=HEAD
Update:
You may also need to use the --reset-author
option,
--reset-author When used with -C/-c/--amend options, declare that the authorship of the resulting commit now belongs of the committer. This also renews the author timestamp.
At first, I answered:
I guess
git commit --reuse-message=HEAD
does it
Then I thought that's not what you wanted and deleted it. Then life caught up and got AFK for a couple of hours. Anyways, despite an answer having already been accepted, I would have suggested:
$ git config alias.troubleshoot '!troubleshoot() { git add -u && git commit -m "Troubleshooting the $1 during deployment to Heroku."; }; troubleshoot'
And you use it the following way:
git troubleshoot foo
Would commit changes (and eventually new files) with "Troubleshooting the foo during deployment to Heroku." as commit message.
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