有没有办法在git提交上重用之前的注释?

Set*_*eth 16 git

有时我会进入故障排除模式并提交/推送一些小而单独的提交,并发表评论,例如"在部署到Heroku期间对<something>进行故障排除".我想为每个提交使用相同的注释,而不必重新键入它.这可能吗?

Ahm*_*ani 21

git-commit(1)命令文档中,

-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.
Run Code Online (Sandbox Code Playgroud)

然后可以使用,

  git commit --reuse-message=HEAD
Run Code Online (Sandbox Code Playgroud)

更新:

您可能还需要使用该--reset-author选项,

--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.
Run Code Online (Sandbox Code Playgroud)


Gre*_*osz 10

起初,我回答说:

我想git commit --reuse-message=HEAD是的

然后我认为这不是你想要的并删除它.然后生活赶上了AFK几个小时.无论如何,尽管已经接受了答案,我建议:

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

您可以通过以下方式使用它:

  1. 修改现有文件
  2. (最终添加未跟踪的文件)
  3. git troubleshoot foo

将使用" 在部署到Heroku期间对foo进行故障排除"提交更改(以及最终的新文件).作为提交消息.


pow*_*wlo 10

.git/COMMIT_EDITMSG 包含最后的提交消息。https://git-scm.com/docs/git-commit#_files

git commit --file .git/COMMIT_EDITMSG
Run Code Online (Sandbox Code Playgroud)

将使用该文件作为提交消息。