Skip to content

Commit db878cd

Browse files
committed
Merge pull request #217 from oldsharp/prq-translate-refspec-original-pull-74
Translate 10-git-internals refspec (Originally #74 )
2 parents acff9e4 + f05549f commit db878cd

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[[_refspec]]
2-
=== The Refspec
2+
=== 引用规格
33

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

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

12-
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:
12+
上述命令会在你的 `.git/config` 文件中添加一个小节,并在其中指定远程版本库的名称(`origin`)、URL 和一个用于获取操作的引用规格(refspec):
1313

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

21-
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.
22-
The `+` tells Git to update the reference even if it isn't a fast-forward.
21+
引用规格的格式由一个可选的 `+` 号和紧随其后的 `<src>:<dst>` 组成,其中 `<src>` 是一个模式(pattern),代表远程版本库中的引用;`<dst>` 是那些远程引用在本地所对应的位置。
22+
`+` 号告诉 Git 即使在不能快进的情况下也要(强制)更新引用。
2323

24-
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.
25-
So, if there is a `master` branch on the server, you can access the log of that branch locally via
24+
默认情况下,引用规格由 `git remote add` 命令自动生成, Git 获取服务器中 `refs/heads/` 下面的所有引用,并将它写入到本地的 `refs/remotes/origin/` 中。
25+
所以,如果服务器上有一个 `master` 分支,我们可以在本地通过下面这种方式来访问该分支上的提交记录:
2626

2727
[source,console]
2828
----
@@ -31,26 +31,26 @@ $ git log remotes/origin/master
3131
$ git log refs/remotes/origin/master
3232
----
3333

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

36-
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
36+
如果想让 Git 每次只拉取远程的 `master` 分支,而不是所有分支,可以把(引用规格的)获取那一行修改为:
3737

3838
[source]
3939
----
4040
fetch = +refs/heads/master:refs/remotes/origin/master
4141
----
4242

43-
This is just the default refspec for `git fetch` for that remote.
44-
If you want to do something one time, you can specify the refspec on the command line, too.
45-
To pull the `master` branch on the remote down to `origin/mymaster` locally, you can run
43+
这仅是针对该远程版本库的 `git fetch` 操作的默认引用规格。
44+
如果有某些只希望被执行一次的操作,我们也可以在命令行指定引用规格。
45+
若要将远程的 `master` 分支拉到本地的 `origin/mymaster` 分支,可以运行:
4646

4747
[source,console]
4848
----
4949
$ git fetch origin master:refs/remotes/origin/mymaster
5050
----
5151

52-
You can also specify multiple refspecs.
53-
On the command line, you can pull down several branches like so:
52+
你也可以指定多个引用规格。
53+
在命令行中,你可以按照如下的方式拉取多个分支:
5454

5555
[source,console]
5656
----
@@ -61,11 +61,11 @@ From [email protected]:schacon/simplegit
6161
* [new branch] topic -> origin/topic
6262
----
6363

64-
In this case, the master branch pull was rejected because it wasn't a fast-forward reference.
65-
You can override that by specifying the `+` in front of the refspec.
64+
在这个例子中,对 `master` 分支的拉取操作被拒绝,因为它不是一个可以快进的引用。
65+
我们可以通过在引用规格之前指定 `+` 号来覆盖该规则。
6666

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

7070
[source,ini]
7171
----
@@ -75,15 +75,15 @@ If you want to always fetch the master and experiment branches, add two lines:
7575
fetch = +refs/heads/experiment:refs/remotes/origin/experiment
7676
----
7777

78-
You can't use partial globs in the pattern, so this would be invalid:
78+
我们不能在模式中使用部分通配符,所以像下面这样的引用规格是不合法的:
7979

8080
[source]
8181
----
8282
fetch = +refs/heads/qa*:refs/remotes/origin/qa*
8383
----
8484

85-
However, you can use namespaces (or directories) to accomplish something like that.
86-
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:
85+
但我们可以使用命名空间(或目录)来达到类似目的。
86+
假设你有一个 QA 团队,他们推送了一系列分支,同时你只想要获取 `master` 和 QA 团队的所有分支而不关心其他任何分支,那么可以使用如下配置:
8787

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

96-
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.
96+
如果项目的工作流很复杂,有 QA 团队推送分支、开发人员推送分支、集成团队推送并且在远程分支上展开协作,你就可以像这样(在本地)为这些分支创建各自的命名空间,非常方便。
9797

9898
[[_pushing_refspecs]]
99-
==== Pushing Refspecs
99+
==== 引用规格推送
100100

101-
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?
102-
You accomplish that by using refspecs to push.
101+
像上面这样从远程版本库获取已在命名空间中的引用当然很棒,但 QA 团队最初应该如何将他们的分支放入远程的 `qa/` 命名空间呢?
102+
我们可以通过引用规格推送来完成这个任务。
103103

104-
If the QA team wants to push their `master` branch to `qa/master` on the remote server, they can run
104+
如果 QA 团队想把他们的 `master` 分支推送到远程服务器的 `qa/master` 分支上,可以运行:
105105

106106
[source,console]
107107
----
108108
$ git push origin master:refs/heads/qa/master
109109
----
110110

111-
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:
111+
如果他们希望 Git 每次运行 `git push origin` 时都像上面这样推送,可以在他们的配置文件中添加一条 `push` 值:
112112

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

121-
Again, this will cause a `git push origin` to push the local `master` branch to the remote `qa/master` branch by default.
121+
正如刚才所指出的,这会让 `git push origin` 默认把本地 `master` 分支推送到远程 `qa/master` 分支。
122122

123-
==== Deleting References
123+
==== 删除引用
124124

125-
You can also use the refspec to delete references from the remote server by running something like this:
125+
你还可以借助类似下面的命令通过引用规格从远程服务器上删除引用:
126126

127127
[source,console]
128128
----
129129
$ git push origin :topic
130130
----
131131

132-
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.
132+
因为引用规格(的格式)是 `<src>:<dst>`,所以上述命令把 `<src>` 留空,意味着把远程版本库的 `topic` 分支定义为空值,也就是删除它。

status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"sections/packfiles.asc": 0,
105105
"sections/plumbing-porcelain.asc": 100,
106106
"sections/refs.asc": 100,
107-
"sections/refspec.asc": 0,
107+
"sections/refspec.asc": 100,
108108
"sections/transfer-protocols.asc": 0
109109
},
110110
"A-git-in-other-environments": {

0 commit comments

Comments
 (0)