Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to reuse/retain commit messages after 'git reset'?

After a git reset, this one-liner can do it:

git commit --reuse-message=HEAD@{1}

or even shorter:

git commit -C HEAD@{1}

You can use the other options given by @user2718704.


When running "git commit" command, you've to check the following options,

To reuse,

--reuse-message=<commit>

To edit on reuse,

--reedit-message=<commit>

To change the author,

--reset-author

Why reset if you can hack, fix, hack and then just run git commit --amend --no-edit; thus, retaining your original commit message.

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.


You could consider git commit --reset-author -c <commit>, to reuse the commit message with editing and the current time.