Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
强制git shell用户名覆盖给定用户名_Git_Git Shell - Fatal编程技术网

强制git shell用户名覆盖给定用户名

强制git shell用户名覆盖给定用户名,git,git-shell,Git,Git Shell,我有一个位于服务器上的裸git存储库和一个使用git shell进行ssh通信的用户 问题是,当我与该用户一起在服务器上推送提交时,无法强制输入用户名和用户电子邮件 我在用户的家中设置~/.gitshrc: export GIT_AUTHOR_NAME="John Doe" export GIT_COMMITTER_NAME="John Doe" 还有~/.gitconfig文件 [user] name = John Doe email = johndoe@example.co

我有一个位于服务器上的裸git存储库和一个使用git shell进行ssh通信的用户

问题是,当我与该用户一起在服务器上推送提交时,无法强制输入用户名和用户电子邮件

我在用户的家中设置~/.gitshrc:

export GIT_AUTHOR_NAME="John Doe"
export GIT_COMMITTER_NAME="John Doe"
还有
~/.gitconfig
文件

[user]
    name = John Doe
    email = johndoe@example.com
但是我在git日志中得到的只是客户端设置的用户名和用户电子邮件


如何在git shell中重写用户名和用户电子邮件?

简单的答案是:你不能。当git将提交推送到远程回购时,它会完全不加更改地推送它。提交者的名称是提交的一部分,因此更改名称将更改提交

不管你怎么做

  • 强制客户端仅使用某些用户名
  • 或者重写提交以具有特定用户名(使用
    git过滤器分支
  • 后者对回购协议的用户来说会有点不方便,因为他们会
    获取
    而不是他们刚刚推送的
    但技术上是可能的。无论如何,我会在
    commit
    push
    阶段保持对名称的简单控制

    如果使用前一种方法,请使用如下git钩子:

    #!/bin/sh
    
    while read oldrev newrev refname; do
        for commit in $(git rev-list $newrev --not $oldrev); do
            USER_NAME=$(git show -s --pretty=format:%an)
            USER_EMAIL=$(git show -s --pretty=format:%ae)
            COMMITTER_NAME=$(git show -s --pretty=format:%cn)
            COMMITTER_EMAIL=$(git show -s --pretty=format:%ce)
            # now perform checks you need and ...
            if <check-failed> ; then
                echo "Some explaining messages"
                exit 1
            fi
        done
    done
    
    #/垃圾箱/垃圾箱
    读取oldrev newrev refname时;做
    对于以$表示的提交(git版本列表$newrev——而不是$oldrev);做
    USER\u NAME=$(git show-s--pretty=格式:%an)
    用户\电子邮件=$(git show-s--pretty=格式:%ae)
    提交者名称=$(git show-s--pretty=格式:%cn)
    提交者\电子邮件=$(git show-s--pretty=格式:%ce)
    #现在执行您需要的检查并。。。
    如果;然后
    回应“一些解释性信息”
    出口1
    fi
    完成
    完成
    
    感谢用户user3159253和其他问题 我成功地进行了以下白名单筛选:

    #!/bin/bash
    #
    #   Git pre-receive hook for validating commits authorship
    #   with linux account full name format : Firstname FULLNAME <email@address>
    #
    #   Adapted from blacklist https://github.com/spuder/git-hooks/blob/master/pre-commit
    #
    
    # Extract full linux user name and email address
    realName=$(getent passwd `whoami`| cut -d ':' -f 5 | cut -d ',' -f 1 |cut -d '<' -f 1|cut -d' ' -f1,2)
    realEmail=$(getent passwd `whoami`| cut -d ':' -f 5 | cut -d ',' -f 1 |cut -d '<' -f 2|cut -d'>' -f1)
    
    check_user() {
         if [[ "$1" != "$realName" ]]; then
          echo "You are commiting $sha1 as $2 $1 user which I don't like. Reveal your identity $realName!"
          exit 1
         fi
    }
    
    check_email() {
         if [[ "$1" != "$realEmail" ]]; then
          echo "You are commiting with $2 email $1 which I don't like. Reveal your email $realEmail!"
          exit 1
         fi
    
    }
    check_commit() {
    
        # Check Author Email
        check_email $(git log -1 --pretty=format:%ae $1) "author"
        # Check Comitter Email
        check_email $(git log -1 --pretty=format:%ce $1) "commiter"
    
        # Check Author Name
        check_user "$(git log -1 --pretty=format:%an $1)" "author"
        # Check Comitter Name
        check_user "$(git log -1 --pretty=format:%cn $1)" "commiter"
    }
    
    
    # Check all incoming commits
    # https://stackoverflow.com/questions/22546393/can-git-pre-receive-hooks-evaulate-the-incoming-commit
    
    NULL_SHA1="0000000000000000000000000000000000000000" # 40 0's
    new_list=
    any_deleted=false
    while read oldsha newsha refname; do
        case $oldsha,$newsha in
        *,$NULL_SHA1) # it's a delete
        any_deleted=true;;
        $NULL_SHA1,*) # it's a create
        new_list="$new_list $newsha";;
        *,*) # it's an update
        new_list="$new_list $newsha";;
        esac
    done
    
    git rev-list $new_list --not --all |
    while read sha1; do
        objtype=$(git cat-file -t $sha1)
        case $objtype in
        commit) check_commit $sha1;;
        esac
    done
    
    #/bin/bash
    #
    #用于验证提交作者身份的Git预接收钩子
    #linux帐户全名格式:Firstname FULLNAME
    #
    #改编自黑名单https://github.com/spuder/git-hooks/blob/master/pre-commit
    #
    #提取完整的linux用户名和电子邮件地址
    
    realName=$(getent passwd`whoami`|cut-d':'-f5 | cut-d','-f1 | cut-d'您能发布git config--list
    返回的内容吗?以下两个命令在终端上有效吗?;$git config--global user.name“John Nash”$git config--global user.emailjohndoe@example.com@karatedog服务器端:git config--list user.name=John Doe user.email=johndoe@example.com客户端:user.name=不是真正的一个用户。email=一些_email@example.com@NishantSingh是的,这就是我用来在gitconfig文件yes中设置选项的地方,这是一个位于push stage服务器端的简单控件这就是我想做的。谢谢你的例子,我会尝试一下。