[英]Replicate git push -m “commit message” with a different command in shell
When I push a commit in to git repository, i need some validations to be happening in the commit message. 当我将提交推送到git仓库时,我需要在提交消息中进行一些验证。 How do i mimic "git push" command with some other? 我如何与其他命令模仿“ git push”命令?
For example have a function in bash profile which gets invoked when i type git push? 例如在bash配置文件中有一个函数,当我键入git push时会被调用? How to have a function in bash profile which can contain space in between function name? 如何在bash配置文件中具有一个可以在函数名称之间包含空格的函数?
When I push a commit in to git repository, i need some validations to be happening in the commit message. 当我将提交推送到git仓库时,我需要在提交消息中进行一些验证。
I would assume you mean when you just commit locally, you want to validate the commit message. 我假设您的意思是,当您仅在本地提交时,您想验证提交消息。 You can do that using Git hooks on the client easily. 您可以使用客户端上的Git挂钩轻松地做到这一点。 More specifically you could use a commit-msg
hook. 更具体地说,您可以使用commit-msg
挂钩。 Here's a good tutorial from the official Git book explaining the process: https://git-scm.com/book/gr/v2/Customizing-Git-An-Example-Git-Enforced-Policy#_client_side_hooks_2 这是Git官方书中的一个很好的教程,解释了该过程: https : //git-scm.com/book/gr/v2/Customizing-Git-An-Example-Git-Enforced-Policy#_client_side_hooks_2
I imagine your case is similar to what they state in the tutorial: 我认为您的情况类似于本教程中的陈述:
The answer to this dilemma is to provide some client-side hooks that users can run to notify them when they're doing something that the server is likely to reject. 解决此难题的方法是提供一些客户端挂钩,用户可以在运行服务器可能拒绝的某些操作时通知它们。
For example have a function in bash profile which gets invoked when i type git push? 例如在bash配置文件中有一个函数,当我键入git push时会被调用? How to have a function in bash profile which can contain space in between function name? 如何在bash配置文件中具有一个可以在函数名称之间包含空格的函数?
I'm not sure what you mean with that, but I suspect you may struggle with Git aliases executing some more complex than a shortcut. 我不确定您的意思是什么,但是我怀疑您可能会因为使用Git别名而不是快捷方式而感到困惑。
You could use !
您可以使用!
to run a shell script. 运行shell脚本。 Here's an example which you can put in our .gitconfig
: 这是一个示例,您可以将其放入.gitconfig
:
[alias]
# Log commits authored by me
mylog = !git log --author=\"$(git config user.name)\"
# Find branches containing commit
fb = "!f() { git branch -a --contains $1; }; f"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.