简体   繁体   English

你如何在同一台机器上使用Git与多个用户?

[英]How do you use Git with multiple users on same machine?

We all know you can set Git email and username in git.config . 我们都知道你可以在git.config设置Git电子邮件和用户名。

What's the best approach when two users use the same machine? 当两个用户使用同一台机器时,最好的方法是什么?

如果您有兴趣在提交时添加用户信息,则可以在每次提交时设置作者。

git commit -m "some message" --author "user2@email.com"

The sequence of actions: 行动顺序:

  1. Create a dedicated group for these two users, and include them into the group. 为这两个用户创建一个专用组,并将其包含在组中。 Re-login to apply the changes, if necessary. 如有必要,请重新登录以应用更改。
  2. Create a shared repo in a location accessible by the users. 在用户可访问的位置创建共享仓库。 with git init --shared git init --shared
  3. Run chown -R :<the_group> . 运行chown -R :<the_group> . inside the repo. 回购里面。
  4. Now your users may clone the repo ( git clone /path/to/the/repo from within their home folders) and work each in their private repo clones with their own personal settings, including name and e-mail. 现在,您的用户可以克隆repo( git clone /path/to/the/repo从他们的主文件夹中),并使用他们自己的个人设置(包括姓名和电子邮件)在私人repo克隆中进行处理。 They need to publish their work periodically with git push . 他们需要定期用git push发布他们的工作。

如果没有单独的用户帐户,我会编写一个GIT_AUTHOR_***设置这些GIT_AUTHOR_***环境变量: httpsGIT_AUTHOR_*** #Committing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM