Skip to content

Translate 04-git-server git-on-a-server #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions book/04-git-server/sections/git-on-a-server.asc
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[[_git_on_the_server]]
=== Getting Git on a Server
[[_git_on_the_server]]
=== 在服务器上搭建 Git

Now we'll cover setting up a Git service running these protocols on your own server.
现在我们将讨论如何在你自己的服务器上搭建 Git 服务来运行这些协议。

[NOTE]
====
Here we'll be demonstrating the commands and steps needed to do basic, simplified installations on a Linux based server, though it's also possible to run these services on Mac or Windows servers too.
Actually setting up a production server within your infrastructure will certainly entail differences in security measures or operating system tools, but hopefully this will give you the general idea of what's involved.
这里我们将要演示在 Linux 服务器上进行一次基本且简化的安装所需的命令与步骤,当然在 Mac Windows 服务器上同样可以运行这些服务。
事实上,在你的计算机基础架构中建立一个生产环境服务器,将不可避免的使用到不同的安全措施与操作系统工具。但是,希望你能从本节中获得一些必要的知识。
====

In order to initially set up any Git server, you have to export an existing repository into a new bare repository – a repository that doesn't contain a working directory.
This is generally straightforward to do.
In order to clone your repository to create a new bare repository, you run the clone command with the `--bare` option.(((git commands, clone, bare)))
By convention, bare repository directories end in `.git`, like so:
在开始架设 Git 服务器前,需要把现有仓库导出为裸仓库——即一个不包含当前工作目录的仓库。
这通常是很简单的。
为了通过克隆你的仓库来创建一个新的裸仓库,你需要在克隆命令后加上 `--bare`选项(((git commands, clone, bare)))
按照惯例,裸仓库目录名以 .git 结尾,就像这样:

[source,console]
----
Expand All @@ -21,40 +21,40 @@ Cloning into bare repository 'my_project.git'...
done.
----

You should now have a copy of the Git directory data in your `my_project.git` directory.
现在,你的 `my_project.git` 目录中应该有 Git 目录的副本了。

This is roughly equivalent to something like
整体上效果大致相当于

[source,console]
----
$ cp -Rf my_project/.git my_project.git
----

There are a couple of minor differences in the configuration file; but for your purpose, this is close to the same thing.
It takes the Git repository by itself, without a working directory, and creates a directory specifically for it alone.
虽然在配置文件中有若干不同,但是对于你的目的来说,这两种方式都是一样的。
它只取出 Git 仓库自身,不要工作目录,然后特别为它单独创建一个目录。

[[_bare_repo]]
==== Putting the Bare Repository on a Server
==== 把裸仓库放到服务器上

Now that you have a bare copy of your repository, all you need to do is put it on a server and set up your protocols.
Let's say you've set up a server called `git.example.com` that you have SSH access to, and you want to store all your Git repositories under the `/opt/git` directory.
Assuming that `/opt/git` exists on that server, you can set up your new repository by copying your bare repository over:
既然你有了裸仓库的副本,剩下要做的就是把裸仓库放到服务器上并设置你的协议。
假设一个域名为 `git.example.com` 的服务器已经架设好,并可以通过 SSH 连接,你想把所有的 Git 仓库放在 `/opt/git` 目录下。
假设服务器上存在 `/opt/git/` 目录,你可以通过以下命令复制你的裸仓库来创建一个新仓库:

[source,console]
----
$ scp -r my_project.git user@git.example.com:/opt/git
----

At this point, other users who have SSH access to the same server which has read-access to the `/opt/git` directory can clone your repository by running
此时,其他通过 SSH 连接这台服务器并对 `/opt/git` 目录拥有可读权限的使用者,通过运行以下命令就可以克隆你的仓库。

[source,console]
----
$ git clone user@git.example.com:/opt/git/my_project.git
----

If a user SSHs into a server and has write access to the `/opt/git/my_project.git` directory, they will also automatically have push access.
如果一个用户,通过使用 SSH 连接到一个服务器,并且其对 `/opt/git/my_project.git` 目录拥有可写权限,那么他将自动拥有推送权限。

Git will automatically add group write permissions to a repository properly if you run the `git init` command with the `--shared` option.(((git commands, init, bare)))
如果到该项目目录中运行 `git init` 命令,并加上 `--shared` 选项,那么 Git 会自动修改该仓库目录的组权限为可写。(((git commands, init, bare)))

[source,console]
----
Expand All @@ -63,38 +63,38 @@ $ cd /opt/git/my_project.git
$ git init --bare --shared
----

You see how easy it is to take a Git repository, create a bare version, and place it on a server to which you and your collaborators have SSH access.
Now you're ready to collaborate on the same project.
由此可见,根据现有的 Git 仓库创建一个裸仓库,然后把它放上你和协作者都有 SSH 访问权的服务器是多么容易。
现在你们已经准备好在同一项目上展开合作了。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应避免出现 你们

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archersmind 如果避免出现了 你们, 那么如何体现 collaborate 呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得 你们 的确比较生硬,但是用在这里还是可以的。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恩,同意


It's important to note that this is literally all you need to do to run a useful Git server to which several people have access – just add SSH-able accounts on a server, and stick a bare repository somewhere that all those users have read and write access to.
You're ready to go – nothing else needed.
值得注意的是,这的确是架设一个几个人拥有连接权的 Git 服务的全部——只要在服务器上加入可以用 SSH 登录的帐号,然后把裸仓库放在大家都有读写权限的地方。
你已经准备好了一切,无需更多。

In the next few sections, you'll see how to expand to more sophisticated setups.
This discussion will include not having to create user accounts for each user, adding public read access to repositories, setting up web UIs, using the Gitosis tool, and more.
However, keep in mind that to collaborate with a couple of people on a private project, all you _need_ is an SSH server and a bare repository.
下面的几节中,你会了解如何扩展到更复杂的设定。
这些内容包含如何避免为每一个用户建立一个账户,给仓库添加公共读取权限,架设网页界面,使用 Gitosis 工具等等。
然而,请记住这一点,如果只是和几个人在一个私有项目上合作的话,__仅仅__ 是一个 SSH 服务器和裸仓库就足够了。

==== Small Setups
==== 小型安装

If you're a small outfit or are just trying out Git in your organization and have only a few developers, things can be simple for you.
One of the most complicated aspects of setting up a Git server is user management.
If you want some repositories to be read-only to certain users and read/write to others, access and permissions can be a bit more difficult to arrange.
如果设备较少或者你只想在小型开发团队里尝试 Git ,那么一切都很简单。
架设 Git 服务最复杂的地方在于用户管理。
如果需要仓库对特定的用户可读,而给另一部分用户读写权限,那么访问和许可安排就会比较困难。

===== SSH Access
===== SSH 连接

(((serving repositories, SSH)))
If you have a server to which all your developers already have SSH access, it's generally easiest to set up your first repository there, because you have to do almost no work (as we covered in the last section).
If you want more complex access control type permissions on your repositories, you can handle them with the normal filesystem permissions of the operating system your server runs.
如果你有一台所有开发者都可以用 SSH 连接的服务器,架设你的第一个仓库就十分简单了,因为你几乎什么都不用做(正如我们上一节所说的)。
如果你想在你的仓库上设置更复杂的访问控制权限,只要使用服务器操作系统的普通的文件系统权限就行了。

If you want to place your repositories on a server that doesn't have accounts for everyone on your team whom you want to have write access, then you must set up SSH access for them.
We assume that if you have a server with which to do this, you already have an SSH server installed, and that's how you're accessing the server.
如果需要团队里的每个人都对仓库有写权限,又不能给每个人在服务器上建立账户,那么提供 SSH 连接就是唯一的选择了。
我们假设用来共享仓库的服务器已经安装了 SSH 服务,而且你通过它访问服务器。

There are a few ways you can give access to everyone on your team.
The first is to set up accounts for everybody, which is straightforward but can be cumbersome.
You may not want to run `adduser` and set temporary passwords for every user.
有几个方法可以使你给团队每个成员提供访问权。
第一个就是给团队里的每个人创建账号,这种方法很直接但也很麻烦。
或许你不会想要为每个人运行一次 `adduser` 并且设置临时密码。

A second method is to create a single 'git' user on the machine, ask every user who is to have write access to send you an SSH public key, and add that key to the `~/.ssh/authorized_keys` file of your new 'git' user.
At that point, everyone will be able to access that machine via the 'git' user.
This doesn't affect the commit data in any way – the SSH user you connect as doesn't affect the commits you've recorded.
第二个办法是在主机上建立一个 'git' 账户,让每个需要写权限的人发送一个 SSH 公钥,然后将其加入 git 账户的 `~/.ssh/authorized_keys` 文件。
这样一来,所有人都将通过 'git' 账户访问主机。
这一点也不会影响提交的数据——访问主机用的身份不会影响提交对象的提交者信息。

Another way to do it is to have your SSH server authenticate from an LDAP server or some other centralized authentication source that you may already have set up.
As long as each user can get shell access on the machine, any SSH authentication mechanism you can think of should work.
另一个办法是让 SSH 服务器通过某个 LDAP 服务,或者其他已经设定好的集中授权机制,来进行授权。
只要每个用户可以获得主机的 shell 访问权限,任何 SSH 授权机制你都可视为是有效的。