Is there a way to amend a commit without vi
(or your $EDITOR
) popping up with the option to modify your commit message, but simply reusing the previous message?
On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.
You can modify the most recent commit in the same branch by running git commit --amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit --amend to modify the most recent commit.
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.
The git commit –amend command lets you modify your last commit. You can change your log message and the files that appear in the commit. The old commit is replaced with a new commit which means that when you amend your old commit it will no longer be visible in the project history.
Since git 1.7.9 version you can also use git commit --amend --no-edit
to get your result.
Note that this will not include metadata from the other commit such as the timestamp which may or may not be important to you.
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