如何检查 git commit 作者是否有效

Giu*_*cin 4 git bash github

在我无法同时设置user.nameuser.email配置的存储库中,我需要使用以下命令编写提交脚本:

commit -a --message "message" --author="author"
Run Code Online (Sandbox Code Playgroud)

消息和作者是参数化的。

当我与错误的作者(不存在rev-list并且格式错误为 git)提交时,我得到:

致命:--author 'bad-formatted-author' 不是 'Name' 并且不匹配任何现有作者

如果作者在提交之前有效,有什么方法可以检查 git 吗?

Rap*_*ert 5

使用git commit -a --message "message" --author="author" --dry-run.

如果给定的选项字符串无效,添加的--dry-run标志将git commit不会实际提交任何内容,但仍会退出非零--author

但是请注意,退出状态非零可能还有其他原因,例如提交为空(即没有任何更改)。