Is there a way to reuse the previous comment for git commit?

Sometimes I go into troubleshooting mode and commit / click a few small but separate commits with a comment like "Troubleshooting <something> during deployment to Heroku." I would like to use the same comment for each commit without re-entering it. Is it possible?

+6
source share
3 answers

First I answered:

I think git commit --reuse-message=HEAD does this

Then I thought it was not what you wanted, and deleted it. Then life caught up and received AFC for a couple of hours. In any case, despite the already accepted answer, I would suggest:

 $ git config alias.troubleshoot '!troubleshoot() { git add -u && git commit -m "Troubleshooting the $1 during deployment to Heroku."; }; troubleshoot' 

And you use it as follows:

  • edit existing files
  • (end up adding files without a trace)
  • git troubleshoot foo

Commit changes (and ultimately new files) using "Troubleshooting foo during deployment to Heroku." as a commit message.

+5
source

From 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. 

Then you can use

  git commit --reuse-message=HEAD 

Update:

You may also need 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. 
+10
source

I'm not sure how you can install a specific git set to use the last git comment you entered, but you can set a default commit message. This can do the trick until you turn off the default commit message as soon as you're done, with all the commits that this message should have used.

Here you can configure the default commit message. First enter the desired commit message into the file, call it ~/LastCommitMessage.txt . Then specify this as the default (global) error message as:

 $ git config --global commit.template ~/LastCommitMessage.txt 

You can narrow the scope by not using -global and using something else instead.

You can easily access all git settings by opening the .gitconfig file located in your home directory. Open this file and delete the above option to disable it after all your commits have completed.

+1
source

Source: https://habr.com/ru/post/952453/


All Articles