[英]How can multiple users use the same directory hierarchy for doing git operations?
我有一个.git / config文件,其中有多个用户定义为:
[user]
name=user1
email=user1@domain.com
name=user2
email=user2@domain.com
...
这是通过执行以下操作创建的:
git config --add user.name user1; git config --add user.email user1@domain.com
git config --add user.name user2; git config --add user.email user2@domain.com
用户user1,user2,...将执行git操作,但绝不会同时进行。
我将GIT_SSH用作从〜/ .ssh / config文件中选择正确信息的脚本:
ARGS=$(awk "/^Host/{flag=0}flag{printf \"-o %s=%s \",\$1,\$2}/Host $GIT_USER_REPO/{flag=1}" ~/.ssh/config)
exec /usr/bin/ssh $ARGS "$@"
如果我只有一个用户,则该部分工作正常。
问题是我不知道如何配置[远程“来源”],以便该URL可以支持多个用户。 我现有的网址仅被指定为一件事:
[remote "origin"]
url = ssh://user1@repo.com:1234/the/path
多个用户如何使用同一目录执行git操作?
在最坏的情况下,我认为$ GIT_SSH指定的脚本可能会修改.git / config文件并动态更新url。 我希望有一个更简单的解决方案。 该解决方案将涉及脚本执行:
请注意,出于这个问题的目的,我对为每个用户创建单独的目录不感兴趣(先执行git clone,然后执行其他git操作)。 将在目录层次结构上操作的“用户”是基于cron的自动化脚本的一部分,并且其中有很多。 就时间和空间而言,为此拥有多个目录是禁止的。 我只想知道我是否可以使用单个目录(带有子目录),并让多个用户在操作永远不会重叠的前提下执行git操作。 谢谢!
我可以确认@manzur和@ etan-reisner所说的都是正确的。
更多信息:查看底层ssh命令是什么时,我看到:
exec /usr/bin/ssh -o User=user1 -o IdentityFile=/path/to/ssh/key -o HostName=repo.com -o StrictHostKeyChecking=no -o UserKnownHostsFile=/path/to/knownhosts -p <port> repo.com git-receive-pack '/repo/path'
因此,我看到用户是通过User = user1字段显式指定的,而不是被git-receive-pack之前的user1@repo.com条目隐式拾取的。 实际上,使用这样的条目,git push将失败。
我的.ssh / config文件包括:
Host user1-repo
User user1
IdentityFile /path/to/ssh/key
HostName repo.com
StrictHostKeyChecking no
UserKnownHostsFile /path/to/knownhosts
您可以从我上面的原始awk命令中看到上述内容如何与上面的exec命令结合,因此如何显式指定User,从而无需让远程URL在URL中指定用户名。
非常感谢您的指导!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.