简体   繁体   中英

git: how to obtain the commit message of the file before it gets committed using pre-commit hook?

I am working on a hook script to get the commit message of the file that is currently being committed and to change the commit message and then commit, if it does not satisfy a pattern.

My question is, Is there a way to get the commit message of the file before it is committed and change the commit message and then commit the file?

The pre-commit hook is intended to check the commited content and not the commit message.

You are probably looking for a prepare-commit-msg hook or more likely a commit-msg hook to make your change to the commit message.

Here is the ordered list of hooks related to the commit action:

  • pre-commit: check commited changes ;
  • prepare-commit-msg: prepare the commit message that can be edited by the user ;
  • commit-msg: check or change the commit message after it has been saved by the user ;
  • post-commit: can be used to send a commit notification.

See the githooks man page for more information about the different hooks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM