简体   繁体   English

在shell中使用不同的命令复制git push -m“提交消息”

[英]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配置文件中具有一个可以在函数名称之间包含空格的函数?

You can look into Git Hooks to do this. 您可以查看Git Hooks来执行此操作。 You can create git hooks for pre-commit , commit-msg , etc. 您可以为pre-commitcommit-msg等创建git钩子。

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.

相关问题 詹金斯如何从git commit消息执行特定的shell命令 - Jenkins how to execute particular shell command from the git commit message 如何退出我的 git 提交消息? 我不在 VIM 中,我使用了“commit -m”命令 - How do I exit my git commit message? I'm NOT in the VIM, I used the " commit -m " command 如何正确地git commit -m&#39;message&#39;或git commit。 -m&#39;消息&#39;? - How to properly git commit -m 'message' OR git commit . -m 'message' ? git push命令,用于将本地提交推送到其他远程分支 - git push command for pushing a local commit to a different remote branch git push提交到不同的分支 - git push commit to different branch git用不同的消息修改提交 - git amend commit with different message 在 git push 之后撤消 2 个不同分支(开发和功能)中的 git 提交消息 - Undo git commit message in 2 different branches (develop and feature) after git push ^ git commit message中的M个字符(git commit -v) - ^M characters in git commit message (git commit -v) 无法运行命令: git add 。 &amp;&amp; git commit -m &quot;初始提交&quot; - Can not run the command: git add . && git commit -m "Initial commit' Git相当于Mercurial“hg commit -A -m <message> ” - Git equivalent of Mercurial “hg commit -A -m <message>”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM