Skip to content

Translate 10-git-internals refspec.asc #74

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

Closed
wants to merge 10 commits into from
57 changes: 24 additions & 33 deletions book/10-git-internals/sections/refspec.asc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[[_refspec]]
=== The Refspec
=== 引用表达式(Refspec

Throughout this book, we've used simple mappings from remote branches to local references, but they can be more complex.
Suppose you add a remote like this:
纵观全书,我们已经使用过一些诸如远程分支到本地引用的简单映射方式,但是还有更复杂的。
假设你添加了这样一个远程版本库:

[source,console]
----
$ git remote add origin https://github.com/schacon/simplegit-progit
----

It adds a section to your `.git/config` file, specifying the name of the remote (`origin`), the URL of the remote repository, and the refspec for fetching:
上面的命令将在你的 `.git/config` 文件中添加一个小节,指定了远程版本库的名称(`origin`)、URL 地址、以及用于获取的引用表达式(Refspec):

[source,ini]
----
Expand All @@ -18,11 +18,9 @@ It adds a section to your `.git/config` file, specifying the name of the remote
fetch = +refs/heads/*:refs/remotes/origin/*
----

The format of the refspec is an optional `+`, followed by `<src>:<dst>`, where `<src>` is the pattern for references on the remote side and `<dst>` is where those references will be written locally.
The `+` tells Git to update the reference even if it isn't a fast-forward.
引用表达式的格式是由一个可选的 `+` 号和 `<src>:<dst>` 组成,这里 `<src>` 是远程上的引用格式, `<dst>` 是将要记录在本地的引用格式。可选的 `+` 号告诉 Git 即使不能快速演进,也要强制更新引用格式。
Copy link
Member

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.

仔细看了一遍:应该是我放错版本了,抱歉。
应该为“引用表达式的格式是由一个可选的 + 号和 <src>:<dst> 组成,这里 <src> 是远程上的参考的式样, <dst> 是那些参考将在本地写在哪里。可选的 + 号告诉 Git 即使不能快速演进,也要强制更新引用。”

Copy link
Member

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.

yes, will update this.


In the default case that is automatically written by a `git remote add` command, Git fetches all the references under `refs/heads/` on the server and writes them to `refs/remotes/origin/` locally.
So, if there is a `master` branch on the server, you can access the log of that branch locally via
默认情况下引用表达式由 `git remote add` 命令自动生成, Git 获取服务器中 `refs/heads/` 下面的所有引用,并将它写入到本地的 `refs/remotes/origin/` 中。 所以,如果服务器上有一个 `master` 分支,即可在本地通过下面这种方式来访问分支记录:

[source,console]
----
Expand All @@ -31,26 +29,23 @@ $ git log remotes/origin/master
$ git log refs/remotes/origin/master
----

They're all equivalent, because Git expands each of them to `refs/remotes/origin/master`.
上面的三个命令作用相同,因为 Git 把它们都扩展成 `refs/remotes/origin/master`

If you want Git instead to pull down only the `master` branch each time, and not every other branch on the remote server, you can change the fetch line to
如果想让 Git 每次只拉取远程的 `master` 分支,而不是所有分支,可以把 fetch 行修改为:

[source]
----
fetch = +refs/heads/master:refs/remotes/origin/master
----

This is just the default refspec for `git fetch` for that remote.
If you want to do something one time, you can specify the refspec on the command line, too.
To pull the `master` branch on the remote down to `origin/mymaster` locally, you can run
这只是针对远程的 `git fetch` 操作的默认引用表达式。如果只想执行一次该操作,可以在命令行指定引用表达式。将远程的 `master` 分支拉取到本地的 `origin/mymaster` 分支,可以运行:
Copy link
Member

Choose a reason for hiding this comment

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

这里是三行英文,怎么你的中文变成一行了?下面很多都有这个问题,需要改一下。
最终提交时的结果是应该有多少行添加了,就有多少行删除了。
可以查看 git diff 的输出结果来确认这点,@@后面的内容必须一致。

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
Member

Choose a reason for hiding this comment

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

这个其实你多虑了,最后生成的书籍里还是一段的!你可以使用 Editing AsciiDoc with Live Preview | Asciidoctor 介绍的工具来实时预览。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks a lot, will update my pull request later today!

Copy link
Member

Choose a reason for hiding this comment

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

你不用重新提交 Pull Request,直接修改完再次提交到同一个分支上就可以。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I know that

Sent from my iPhone

On 2015年6月16日, at 下午03:39, "狂飙" notifications@github.com wrote:

In book/10-git-internals/sections/refspec.asc:

[source]


fetch = +refs/heads/master:refs/remotes/origin/master


-This is just the default refspec for git fetch for that remote.
-If you want to do something one time, you can specify the refspec on the command line, too.
-To pull the master branch on the remote down to origin/mymaster locally, you can run
+这只是针对远程的 git fetch 操作的默认引用表达式。如果只想执行一次该操作,可以在命令行指定引用表达式。将远程的 master 分支拉取到本地的 origin/mymaster 分支,可以运行:
你不用重新提交 Pull Request,直接修改完再次提交到同一个分支上就可以。


Reply to this email directly or view it on GitHub.


[source,console]
----
$ git fetch origin master:refs/remotes/origin/mymaster
----

You can also specify multiple refspecs.
On the command line, you can pull down several branches like so:
你也可以指定多个引用表达式。使用命令行,你可以按照如下的方式拉取多个分支:

[source,console]
----
Expand All @@ -61,11 +56,9 @@ From git@github.com:schacon/simplegit
* [new branch] topic -> origin/topic
----

In this case, the master branch pull was rejected because it wasn't a fast-forward reference.
You can override that by specifying the `+` in front of the refspec.
在这个例子中,`master` 分支的拉取操作被拒绝,因为该分支不是一个可以快速演进的引用。可以通过在引用表达式之前使用 `+` 号来强制更新。

You can also specify multiple refspecs for fetching in your configuration file.
If you want to always fetch the master and experiment branches, add two lines:
你也可以在配置文件中指定多个引用表达式。如果想在每次获取时都包括 `master` 和 `experiment` 分支,添加如下两行:

[source,ini]
----
Expand All @@ -75,15 +68,15 @@ If you want to always fetch the master and experiment branches, add two lines:
fetch = +refs/heads/experiment:refs/remotes/origin/experiment
----

You can't use partial globs in the pattern, so this would be invalid:
注意这里不能使用部分通配符,所以下面这样就是不合法的:

[source]
----
fetch = +refs/heads/qa*:refs/remotes/origin/qa*
----

However, you can use namespaces (or directories) to accomplish something like that.
If you have a QA team that pushes a series of branches, and you want to get the master branch and any of the QA team's branches but nothing else, you can use a config section like this:
但可以使用命名空间(或目录)来达到这个目的。
如果你有一个 QA 团队,推送了一系列分支,而你只要获取 master QA 团队的这些分支,那么,你可以使用如下的配置:

[source,ini]
----
Expand All @@ -93,22 +86,20 @@ If you have a QA team that pushes a series of branches, and you want to get the
fetch = +refs/heads/qa/*:refs/remotes/origin/qa/*
----

If you have a complex workflow process that has a QA team pushing branches, developers pushing branches, and integration teams pushing and collaborating on remote branches, you can namespace them easily this way.
如果工作流很复杂,有 QA 团队推送的分支、开发人员推送的分支、还有集成团队推送并且在远程分支上协作,可以为他们创建各自的命名空间解决类似问题。

[[_pushing_refspecs]]
==== Pushing Refspecs
==== 推送引用表达式

It's nice that you can fetch namespaced references that way, but how does the QA team get their branches into a `qa/` namespace in the first place?
You accomplish that by using refspecs to push.

If the QA team wants to push their `master` branch to `qa/master` on the remote server, they can run
采用命名空间的方式来获取分支是个好主意,但 QA 团队一开始如何将他们的分支推送到 `qa/` 命名空间呢?答案是通过引用表达式的推送来完成。
如果 QA 团队想把他们的 `master` 分支推送到远程服务器的 `qa/master` 分支上,可以运行:

[source,console]
----
$ git push origin master:refs/heads/qa/master
----

If they want Git to do that automatically each time they run `git push origin`, they can add a `push` value to their config file:
如果他们希望 Git 每次运行 `git push origin` 时都如上这样推送,他们可以在配置文件中添加一个 `push` 值:

[source,ini]
----
Expand All @@ -118,15 +109,15 @@ If they want Git to do that automatically each time they run `git push origin`,
push = refs/heads/master:refs/heads/qa/master
----

Again, this will cause a `git push origin` to push the local `master` branch to the remote `qa/master` branch by default.
同样的,这会让 `git push origin` 默认把本地 `master` 分支推送到远程 `qa/master` 分支。

==== Deleting References
==== 删除引用

You can also use the refspec to delete references from the remote server by running something like this:
你也可以使用引用表达式来删除远程服务器的引用,运行如下命令:

[source,console]
----
$ git push origin :topic
----

Because the refspec is `<src>:<dst>`, by leaving off the `<src>` part, this basically says to make the topic branch on the remote nothing, which deletes it.
因为引用表达式的格式是 `<src>:<dst>`, 所以把 `<src>` 留空的意思就是把远程的 `topic` 分支定义为空值,也就是删除它。