在本地执行的Git拉钩脚本 [英] Git pull hook script which executes locally

查看:63
本文介绍了在本地执行的Git拉钩脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提示每一个与git服务器联系的命令git push和pull的确认[是/否].有没有办法包括任何命令/脚本来实现这一目标?因此,在此操作之后,只有git继续进行,用户才能给出输入.

I want to prompt for the confirmation [yes/no] for every the commands git push and pull which contacts the git server. Is there a way to include any commands/scripts to make this happen? so User can able to given the input, after that only git proceeds for that operation.

推荐答案

首先,我认为您不会因此改变而结交很多朋友.如果有人键入git pull,则他已经证明自己愿意与远程服务器联系.我认为,在这种情况下,无需通过确认对话框来烦扰用户.

First of all, I don't think that you will make much friends with that change. If someone types in git pull, he already proved that he's willing to contact the remote server. In my opinion, there's no need to annoy the user with confirm dialogs in that case.

无论如何,如果您想要确认每个pullpush,则钩子不是正确的工具,因为拉/推钩子仅存在于服务器端.客户端上没有pre-pullpost-pullpre-pushpost-push挂钩.因此,我们必须放弃这个钩子"想法.

Anyway, if you want to confirm every pull and push, hooks are not the right tool since the pull/push hooks only exist on the server side. There are no pre-pull, post-pull, pre-push or post-push hooks on the client side. So, we have to discard the hook idea.

您可以别名 pullpush命令而不是用查询包围它们,是否真的应该拉/推.

You could alias the pull and push commands instead to surround them with the query whether there should really be pulled/pushed or not.

查询很简单:

echo -n "really push? [y/n] "
read -s -n 1 really
if [[ $really == "y" ]]; then 
  # PULL/PUSH HERE
else 
  echo "aborting"
fi

不幸的是,您不能为别名使用相同的名称.所以,

Unfortunately, you can't use the same name for an alias. So, the easy thought of

[alias]
    push = "!echo -n \"really push? [y/n]\";read -s -n 1 really;if [[ $really == \"y\" ]];then git push; else echo \"aborting\"; fi"

不起作用.

但是,您还有两个选择可以实现所需的目标:

But you have two other options to achieve what you want:

  • 使用git bord表示并调用别名safepush/safepull或类似的名称
  • .bashrc中为git pullgit push设置别名(请参见 SU上的这个问题,用于设置实际上是功能的多词别名)
  • use git bord means and call the alias safepush/safepull or something like that
  • set up an alias in your .bashrc for git pull and git push (see this question on SU for setting up multiword aliases which are actually functions)

这篇关于在本地执行的Git拉钩脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆