是否可以自定义.gitignore?只读访问权限?

问题描述

| 我在团队环境中工作,已经有一个“ 0”文件。 我想将更多项目添加到“ 0”文件中,但是我不想在任何一个中检查该文件。可以设置仅适用于我的自定义忽略文件? 另外,我想授予某人对我们服务器上私有git存储库的只读访问权限,如果我将他们的SSH密钥添加到我们的服务器中,他们将像其他所有人一样获得完全访问权限。如何将其限制为只读,不允许提交。     

解决方法

将您的私人忽略规则放在
.git/info/exclude
中。参见
gitignore(5)
。 对于只读访问,请使用
git-daemon
,Web服务器或Gitosis或Gitolite。     ,我知道我的谈话时间有些晚,但是您可能要考虑使用
git update-index --assume-unchanged [ FILE ]
如git帮助文档所述:   当“假定未更改”位打开时,git停止检查工作树文件是否可能进行修改,因此您需要手动取消设置该位以在更改工作树文件时告诉git ... 强调我的。继续说   此选项可以用作粗略的文件级机制,以忽略跟踪文件中未提交的更改(类似于.gitignore对未跟踪文件所做的操作)。如果需要修改索引中的该文件,Git将失败(正常)。合并提交时;因此,如果假定未跟踪的文件在上游被更改,则您将需要手动处理这种情况。 因此,请记住,您将必须知道对这些文件所做的任何上游更改。 如果您想再次开始跟踪文件,则只需使用
git update-index --no-assume-unchange [ FILE ]
希望对以后的读者有帮助。     ,对于ssh部分,您应该考虑使用Gitolite(替代gitosis)。     ,就像Fred Frodo所说的那样,您可以将私有排除规则放在存储库的“ 2”中。 如果要对计算机上的所有存储库应用相同的排除规则,则可以将以下内容添加到用户目录中的
.gitconfig
文件中。
[core]       
    excludesfile = /home/<myusername>/.gitexclude 
然后将排除模式添加到
~/.gitexclude
。     ,您可能对Junio编写且Carl进行了改进的更新挂钩感兴趣。将下面的代码放在ѭ11中,不要忘了通过ѭ12启用它。
#!/bin/bash

umask 002

# If you are having trouble with this access control hook script
# you can try setting this to true.  It will tell you exactly
# why a user is being allowed/denied access.

verbose=false

# Default shell globbing messes things up downstream
GLOBIGNORE=*

function grant {
  $verbose && echo >&2 \"-Grant-     $1\"
  echo grant
  exit 0
}

function deny {
  $verbose && echo >&2 \"-Deny-      $1\"
  echo deny
  exit 1
}

function info {
  $verbose && echo >&2 \"-Info-      $1\"
}

# Implement generic branch and tag policies.
# - Tags should not be updated once created.
# - Branches should only be fast-forwarded unless their pattern starts with \'+\'
case \"$1\" in
  refs/tags/*)
    git rev-parse --verify -q \"$1\" &&
    deny >/dev/null \"You can\'t overwrite an existing tag\"
    ;;
  refs/heads/*)
    # No rebasing or rewinding
    if expr \"$2\" : \'0*$\' >/dev/null; then
      info \"The branch \'$1\' is new...\"
    else
      # updating -- make sure it is a fast-forward
      mb=$(git-merge-base \"$2\" \"$3\")
      case \"$mb,$2\" in
        \"$2,$mb\") info \"Update is fast-forward\" ;;
    *)    noff=y; info \"This is not a fast-forward update.\";;
      esac
    fi
    ;;
  *)
    deny >/dev/null \\
    \"Branch is not under refs/heads or refs/tags.  What are you trying to do?\"
    ;;
esac

# Implement per-branch controls based on username
allowed_users_file=$GIT_DIR/info/allowed-users
username=$(id -u -n)
info \"The user is: \'$username\'\"

if test -f \"$allowed_users_file\"
then
  rc=$(cat $allowed_users_file | grep -v \'^#\' | grep -v \'^$\' |
    while read heads user_patterns
    do
      # does this rule apply to us?
      head_pattern=${heads#+}
      matchlen=$(expr \"$1\" : \"${head_pattern#+}\")
      test \"$matchlen\" = ${#1} || continue

      # if non-ff,$heads must be with the \'+\' prefix
      test -n \"$noff\" &&
      test \"$head_pattern\" = \"$heads\" && continue

      info \"Found matching head pattern: \'$head_pattern\'\"
      for user_pattern in $user_patterns; do
    info \"Checking user: \'$username\' against pattern: \'$user_pattern\'\"
    matchlen=$(expr \"$username\" : \"$user_pattern\")
    if test \"$matchlen\" = \"${#username}\"
    then
      grant \"Allowing user: \'$username\' with pattern: \'$user_pattern\'\"
    fi
      done
      deny \"The user is not in the access list for this branch\"
    done
  )
  case \"$rc\" in
    grant) grant >/dev/null \"Granting access based on $allowed_users_file\" ;;
    deny)  deny  >/dev/null \"Denying  access based on $allowed_users_file\" ;;
    *) ;;
  esac
fi

allowed_groups_file=$GIT_DIR/info/allowed-groups
groups=$(id -G -n)
info \"The user belongs to the following groups:\"
info \"\'$groups\'\"

if test -f \"$allowed_groups_file\"
then
  rc=$(cat $allowed_groups_file | grep -v \'^#\' | grep -v \'^$\' |
    while read heads group_patterns
    do
      # does this rule apply to us?
      head_pattern=${heads#+}
      matchlen=$(expr \"$1\" : \"${head_pattern#+}\")
      test \"$matchlen\" = ${#1} || continue

      # if non-ff,$heads must be with the \'+\' prefix
      test -n \"$noff\" &&
      test \"$head_pattern\" = \"$heads\" && continue

      info \"Found matching head pattern: \'$head_pattern\'\"
      for group_pattern in $group_patterns; do
    for groupname in $groups; do
      info \"Checking group: \'$groupname\' against pattern: \'$group_pattern\'\"
      matchlen=$(expr \"$groupname\" : \"$group_pattern\")
      if test \"$matchlen\" = \"${#groupname}\"
      then
        grant \"Allowing group: \'$groupname\' with pattern: \'$group_pattern\'\"
      fi
        done
      done
      deny \"None of the user\'s groups are in the access list for this branch\"
    done
  )
  case \"$rc\" in
    grant) grant >/dev/null \"Granting access based on $allowed_groups_file\" ;;
    deny)  deny  >/dev/null \"Denying  access based on $allowed_groups_file\" ;;
    *) ;;
  esac
fi

deny >/dev/null \"There are no more rules to check.  Denying access\"
有了此钩子之后,您便可以为特定的用户或组提供对存储库的更改。可以看到它的其他任何人都具有只读访问权限。   它使用两个文件
$GIT_DIR/info/allowed-users
allowed-groups
来描述哪些头可以由谁推入。每个文件的格式如下:
refs/heads/master  junio
+refs/heads/pu     junio
refs/heads/cogito$ pasky
refs/heads/bw/.*   linus
refs/heads/tmp/.*  .*
refs/tags/v[0-9].* junio
     这样,Linus可以推动或创建
bw/penguin
bw/zebra
bw/panda
分支,Pasky只能执行
cogito
,JC可以执行
master
pu
分支并制作版本标记。任何人都可以做23个分支。
pu
记录上的“ +”号表示JC可以对其进行非快进推送。 如果此人尚未访问您的存储库所在的主机,则该人应仅具有“ 25”访问权限,而不是无限制访问权限。创建一个特殊用途的git用户,并在ѭ26中,以以下形式添加局外人的SSH密钥。请注意,该键应该在一条长线上,但是我将其包裹在下面以帮助演示。 没有代理转发,没有端口转发,没有pty,没有X11转发, 命令= \“ env myorg_git_user = joeuser / usr / local / bin / git-shell -c \\\“ $ {SSH_ORIGINAL_COMMAND:-} \\\” \“ ssh-rsa AAAAB3 ... 2iQ == joeuser@foo.invalid 根据您的本地设置,您可能需要将路径调整为
git-shell
。请记住,
sshd
与about29ѭ目录的权限高度偏执,因此请关闭其组写入位及其下的所有文件。 通过git用户向每个人传递信息意味着您需要能够区分别人,这是
myorg_git_user
环境变量的目的。而不是依赖无条件的
username=$(id -u -n)
,请调整更新挂钩以使用它:
# Implement per-branch controls based on username
allowed_users_file=$GIT_DIR/info/allowed-users
if [ -z \"$myorg_git_user\" ]; then
  username=$(id -u -n)
else
  username=$myorg_git_user
fi
info \"The user is: \'$username\'\"
通过此设置,具有只读访问权限的朋友将使用类似于以下命令的命令克隆。具体路径取决于您的设置。为了使路径更好,可以将您的存储库重新放置到git用户的主目录中,或者创建一个指向它的符号链接。 $ git clone git@blankman.com.invalid:coolproject.git 但将无法进行更新。 $ git push origin mybranch 总计0(增量0),重用0(增量0) 远程:错误:挂钩拒绝更新参考/头/ mybranch 到git@blankman.com.invalid:coolproject.git  ! [远程拒绝] mybranch-> mybranch(挂钩被拒绝) 错误:无法将某些引用推送到\'git@blankman.com.invalid:coolproject.git \' 您说您正在团队环境中工作,所以我假设您的中央存储库是使用
--shared
选项创建的。 (请参阅
git config
文档中的
core.sharedRepository
git init
文档中的
--shared
。)确保新的git用户是系统组的成员,该组允许您所有人访问中央存储库。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...