![](/img/trans.png)
[英]How can I append a line to a git commit message from the command line?
[英]How do I disable being able to set the git commit message from the command line?
我发现能够一次性指定提交消息,欺骗我编写简短的一行提交消息。 我常常按照git commit -m "fix things"
。 但每当我放弃-m
选项,并且我的编辑器弹出时,我更有可能写一个好的提交消息。
在过去,我通过禁用我不想再使用的功能来创造习惯。 例如:我在vim中禁用了箭头键,这最终让我使用了hjkl。 这非常有效,我想尝试为git commit消息做同样的事情。 我希望git(或bash或zsh)对我大喊大叫,试图使用commit -m
。
我可以完全围绕git命令编写一个包装器,但也许你有其他的解决方案,我可能会学到一些很酷的东西! 我对各种魔法和诡计持开放态度。
您可以在.git/hooks
目录中创建prepare-commit-msg
挂钩,以检查消息的长度,如果消息太短,则拒绝提交:
#!/bin/bash
# Remove whitespace, at least 50 characters should remain.
if (( $(sed 's/\s//g' "$1" | wc -c) < 50 )) ; then
echo Message too short. >&2
exit 1
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.