From 5e9b67845ef8c04758bbd0bbbc2afdb98d4171b9 Mon Sep 17 00:00:00 2001 From: Yue Lin Ho Date: Fri, 29 Apr 2016 07:56:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E7=AB=A0=20=E7=AC=AC?= =?UTF-8?q?=E4=BA=94=E7=AF=80=20=E9=81=A0=E7=AB=AF=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sections/remote-branches.asc | 194 +++++++++--------- status.json | 2 +- 2 files changed, 98 insertions(+), 98 deletions(-) diff --git a/book/03-git-branching/sections/remote-branches.asc b/book/03-git-branching/sections/remote-branches.asc index 0e80543..535c8c5 100644 --- a/book/03-git-branching/sections/remote-branches.asc +++ b/book/03-git-branching/sections/remote-branches.asc @@ -2,70 +2,70 @@ === 遠端分支 (((branches, remote)))(((references, remote))) -Remote references are references (pointers) in your remote repositories, including branches, tags, and so on. -You can get a full list of remote references explicitly with `git ls-remote [remote]`, or `git remote show [remote]` for remote branches as well as more information. -Nevertheless, a more common way is to take advantage of remote-tracking branches. +遠端參照是位於遠端版本庫上的參照,包括分支、標籤等等; +你可以使用 `git ls-remote [remote]` 明確地列出遠端參照完整的列表,或者使用 `git remote show [remote]` 取得更多遠端分支資訊; +然而,更好的方式是利用「遠端追蹤分支」。 -Remote-tracking branches are references to the state of remote branches. -They're local references that you can't move; they're moved automatically for you whenever you do any network communication. -Remote-tracking branches act as bookmarks to remind you where the branches in your remote repositories were the last time you connected to them. +遠端追蹤分支用來記錄遠端分支的狀態, +它們是無法移動的本地參照,但是會根據網路通訊的結果而自動移動; +它扮演著書籤的角色,用來提醒你上次與遠端通訊後那些遠端上的分支所在之處。 -They take the form `(remote)/(branch)`. -For instance, if you wanted to see what the `master` branch on your `origin` remote looked like as of the last time you communicated with it, you would check the `origin/master` branch. -If you were working on an issue with a partner and they pushed up an `iss53` branch, you might have your own local `iss53` branch; but the branch on the server would point to the commit at `origin/iss53`. +它們採用 `(遠端)/(分支)` 這樣的形式, +例如,你想看上次與 `origin` 版本庫通訊後,它的 `master` 分支指向哪一個提交,你應該查看 `origin/master` 分支; +如果你和同伴一起修正某個議題,而他先推送 `iss53` 分支到遠端版本庫;雖然在你的本地端可能也有一個 `iss53` 分支,但伺服器上的 `iss53` 分支會跟 `origin/iss53` 指向同一個提交。 -This may be a bit confusing, so let's look at an example. -Let's say you have a Git server on your network at `git.ourcompany.com`. -If you clone from this, Git's `clone` command automatically names it `origin` for you, pulls down all its data, creates a pointer to where its `master` branch is, and names it `origin/master` locally. -Git also gives you your own local `master` branch starting at the same place as origin's `master` branch, so you have something to work from. +可能有點令人困惑,所以讓我們直接舉例說明; +假設你的網路有一個 Git 伺服器位於 `git.ourcompany.com`, +你從這裡克隆時,Git 的 `clone` 命令會自動幫你把這個遠端版本庫命名為 `origin`,下載其中所有的資料,建立一個本地的 `origin/master` 並指向遠端的 `master` 分支所指向的同一個提交; +Git 也會建立屬於你自己的 `master` 本地分支,同樣地,它也指向同一個提交,以便讓你可以從這裡開始工作。 [NOTE] -.``origin'' is not special +.「origin」並不特別 ==== -Just like the branch name ``master'' does not have any special meaning in Git, neither does ``origin''. -While ``master'' is the default name for a starting branch when you run `git init` which is the only reason it's widely used, ``origin'' is the default name for a remote when you run `git clone`. -If you run `git clone -o booyah` instead, then you will have `booyah/master` as your default remote branch.(((origin))) +就像分支名稱「master」在 Git 中並沒有特別的含意,「origin」同樣也並不特別; +「master」會被廣泛地使用的唯一理由只是在執行 `git init` 時使用了預設的「master」做為起始的分支;同樣地,「origin」也只是在執行 `git clone` 時所使用的預設遠端簡稱。 +如果你執行 `git clone -o booyah`,預設的遠端追蹤分支將會是 `booyah/master`。(((origin))) ==== -.Server and local repositories after cloning -image::images/remote-branches-1.png[Server and local repositories after cloning.] +.克隆後,伺服器和本地端的版本庫 +image::images/remote-branches-1.png[克隆後,伺服器和本地端的版本庫。] -If you do some work on your local `master` branch, and, in the meantime, someone else pushes to `git.ourcompany.com` and updates its `master` branch, then your histories move forward differently. -Also, as long as you stay out of contact with your origin server, your `origin/master` pointer doesn't move. +如果你在本地分支 `master` 做了一些工作,與此同時,有人推送到 `git.ourcompany.com` 而更新了伺服器上的 `master` 分支,這會讓你的提交歷史朝著不同方向發展; +不過只要你不和伺服器連絡,你的 `origin/master` 指標並不會移動。 -.Local and remote work can diverge -image::images/remote-branches-2.png[Local and remote work can diverge.] +.本地和遠端的歷史分離開來 +image::images/remote-branches-2.png[本地和遠端的歷史分離開來。] -To synchronize your work, you run a `git fetch origin` command. -This command looks up which server ``origin'' is (in this case, it's `git.ourcompany.com`), fetches any data from it that you don't yet have, and updates your local database, moving your `origin/master` pointer to its new, more up-to-date position. +執行 `git fetch origin` 可以同步遠端伺服器上的資料到本地, +該命令首先尋找 `origin` 是哪個伺服器(本例是 `git.ourcompany.com`),從上面獲取你尚未擁有的資料,更新你本地的資料庫,然後把 `origin/master` 指標同步到最新的位置。 -.`git fetch` updates your remote references -image::images/remote-branches-3.png[`git fetch` updates your remote references.] +.`git fetch` 會更新你的遠端參照 +image::images/remote-branches-3.png[`git fetch` 會更新你的遠端參照。] -To demonstrate having multiple remote servers and what remote branches for those remote projects look like, let's assume you have another internal Git server that is used only for development by one of your sprint teams. -This server is at `git.team1.ourcompany.com`. -You can add it as a new remote reference to the project you're currently working on by running the `git remote add` command as we covered in <<_git_basics_chapter>>. -Name this remote `teamone`, which will be your shortname for that whole URL. +為了演示在擁有多個遠端伺服器的情況下,這些遠端專案的遠端分支看起來會長什麼樣,我們假設你還有另一個僅供你的敏捷開發小組使用的內部 Git 伺服器, +這個伺服器位於 `git.team1.ourcompany.com`, +你可以用我們在 <<_git_basics_chapter>> 中所提到的 `git remote add` 命令為目前的案案加入一個新的遠端版本庫, +並把它命名為 `teamone` 以做為那個完整的 URL 的簡稱。 -.Adding another server as a remote -image::images/remote-branches-4.png[Adding another server as a remote.] +.加入另一個遠端伺服器 +image::images/remote-branches-4.png[加入另一個遠端伺服器。] -Now, you can run `git fetch teamone` to fetch everything the remote `teamone` server has that you don't have yet. -Because that server has a subset of the data your `origin` server has right now, Git fetches no data but sets a remote-tracking branch called `teamone/master` to point to the commit that `teamone` has as its `master` branch. +現在你可以用 `git fetch teamone` 來取得 `teamone` 伺服器上你還沒有的資料了, +由於那個伺服器上的內容是 `origin` 伺服器上的子集合,Git 並不會下載任何資料,但是會建立一個名為 `teamone/master` 的遠端追蹤分支,指向 `teamone` 伺服器的 `master` 分支所指向的同一個提交。 -.Remote tracking branch for `teamone/master` -image::images/remote-branches-5.png[Remote tracking branch for `teamone/master`.] +.遠端追蹤分支 `teamone/master` +image::images/remote-branches-5.png[遠端追蹤分支 `teamone/master`。] [[_pushing_branches]] -==== Pushing +==== 推送的用法 (((pushing))) -When you want to share a branch with the world, you need to push it up to a remote that you have write access to. -Your local branches aren't automatically synchronized to the remotes you write to – you have to explicitly push the branches you want to share. -That way, you can use private branches for work you don't want to share, and push up only the topic branches you want to collaborate on. +當你想跟世界分享某個分支,你需要把它推送到一個你擁有寫入權限的遠端版本庫; +你的本地分支並不會自動同步到遠端上——你必需明確地推送你想分享的分支; +透過這種方式,你可以將無意分享的分支保留下來做為私用分支,而只推送需要協同工作的主題分支。 -If you have a branch named `serverfix` that you want to work on with others, you can push it up the same way you pushed your first branch. -Run `git push `:(((git commands, push))) +如果你有個叫做 `serverfix` 的分支需要和其他人一起開發, +執行 `git push <遠端> <分支>`:(((git commands, push))) [source,console] ---- @@ -79,26 +79,26 @@ To https://github.com/schacon/simplegit * [new branch] serverfix -> serverfix ---- -This is a bit of a shortcut. -Git automatically expands the `serverfix` branchname out to `refs/heads/serverfix:refs/heads/serverfix`, which means, ``Take my serverfix local branch and push it to update the remote's serverfix branch.'' -We'll go over the `refs/heads/` part in detail in <<_git_internals>>, but you can generally leave it off. -You can also do `git push origin serverfix:serverfix`, which does the same thing – it says, ``Take my serverfix and make it the remote's serverfix.'' -You can use this format to push a local branch into a remote branch that is named differently. -If you didn't want it to be called `serverfix` on the remote, you could instead run `git push origin serverfix:awesomebranch` to push your local `serverfix` branch to the `awesomebranch` branch on the remote project. +這裡其實走了一點捷徑, +Git 會把 `serverfix` 分支名稱自動地擴展為 `refs/heads/serverfix:refs/heads/serverfix`,意思是:「使用本地端的 serverfix 分支推送,以更新遠端的 serverfix 分支」(譯註:冒號之前是本地端,冒號之後是遠端); +我們將在 <<_git_internals>> 進一步介紹 `refs/heads/` 的細節,不過一般來說你可以先將它拋在腦後。 +執行 `git push origin serverfix:serverfix` 也會做相同的事——它的意思是:「使用本地端的 serverfix 分支建立遠端的 serverfix 分支」; +你可以用這種格式把本地分支推送到遠端的異名分支, +假設你不想在遠端把它叫做 `serverfix`,可以用 `git push origin serverfix:awesomebranch` 將本地端的 `serverfix` 分支推送到遠端專案的 `awesomebranch` 分支。 [NOTE] -.Don't type your password every time +.不想每次都輸入密碼 ==== -If you're using an HTTPS URL to push over, the Git server will ask you for your username and password for authentication. -By default it will prompt you on the terminal for this information so the server can tell if you're allowed to push. +如果你正在使用 HTTPS URL 推送資料,Git 伺服器為了核對身份會詢問你的帳號和密碼; +預設情況它會在終端提示你輸入相關資訊,這樣伺服器才能分辨你是否有推送權限。 -If you don't want to type it every single time you push, you can set up a ``credential cache''. -The simplest is just to keep it in memory for a few minutes, which you can easily set up by running `git config --global credential.helper cache`. +如果你不想每次推送時都輸入它們,你可以設置「證書快取」; +最簡單的方式是執行 `git config --global credential.helper cache` 將它保留記憶體幾分鐘。 -For more information on the various credential caching options available, see <<_credential_caching>>. +詳見 <<_credential_caching>> 以取得各種可使用的、詳細的證書快取方式。 ==== -The next time one of your collaborators fetches from the server, they will get a reference to where the server's version of `serverfix` is under the remote branch `origin/serverfix`: +當你的協作者下次從伺服器上獲取資料時,他們將得到一個新的遠端追蹤分支 `origin/serverfix` 指向伺服器上的 `serverfix` 所指向的同一個版本: [source,console] ---- @@ -111,11 +111,11 @@ From https://github.com/schacon/simplegit * [new branch] serverfix -> origin/serverfix ---- -It's important to note that when you do a fetch that brings down new remote-tracking branches, you don't automatically have local, editable copies of them. -In other words, in this case, you don't have a new `serverfix` branch – you only have an `origin/serverfix` pointer that you can't modify. +有一點很重要請注意:`fetch` 操作會產生新的遠端追蹤分支,但是並不會自動產生本地分支; +換句話說,在本例中,你不會有一個新的 `serverfix` 分支——你只會有一個無法更動的 `origin/serverfix` 指標。 -To merge this work into your current working branch, you can run `git merge origin/serverfix`. -If you want your own `serverfix` branch that you can work on, you can base it off your remote-tracking branch: +執行 `git merge origin/serverfix` 可以把 `origin/serverfix` 的內容合併到目前分支; +如果想要一個你自己的 `serverfix` 分支用來開發,可以在遠端分支的基礎上分化出一個本地分支: [source,console] ---- @@ -124,20 +124,20 @@ Branch serverfix set up to track remote branch serverfix from origin. Switched to a new branch 'serverfix' ---- -This gives you a local branch that you can work on that starts where `origin/serverfix` is. +它會給你一個本地分支 `serverfix`,並且可以在 `origin/serverfix` 的基礎上繼續開發。 [[_tracking_branches]] -==== Tracking Branches +==== 追蹤分支 (((branches, tracking)))(((branches, upstream))) -Checking out a local branch from a remote-tracking branch automatically creates what is called a ``tracking branch'' (and the branch it tracks is called an ``upstream branch''). -Tracking branches are local branches that have a direct relationship to a remote branch. -If you're on a tracking branch and type `git pull`, Git automatically knows which server to fetch from and branch to merge into. +從遠端追蹤分支身上檢出的本地分支會自動升級為「追蹤分支」(它所追蹤的分支則稱為「上游分支」), +追蹤分支是一種和某個遠端分支有直接聯繫的本地分支; +如果你切換到追蹤分支並執行 `git pull`,Git 會自動分辨要從哪一個伺服器獲取資料,然後自動辨別要合併哪一個分支進來(譯註:就是合併上游分支)。 -When you clone a repository, it generally automatically creates a `master` branch that tracks `origin/master`. -However, you can set up other tracking branches if you wish – ones that track branches on other remotes, or don't track the `master` branch. -The simple case is the example you just saw, running `git checkout -b [branch] [remotename]/[branch]`. -This is a common enough operation that git provides the `--track` shorthand: +在克隆一個版本庫時,Git 通常會自動建立一個名為 `master` 的分支用來追蹤 `origin/master`; +然而,如果你想要的話,你可以設定其它追蹤分支——改變追蹤其它遠端上的分支,或者不再追蹤遠端的 `master` 分支。 +`git checkout -b [分支] [遠端]/[分支]` 是一個你剛剛才看過的簡單例子, +你還可以用一個相當常用的 `--track` 選項簡化這個操作: [source,console] ---- @@ -146,7 +146,7 @@ Branch serverfix set up to track remote branch serverfix from origin. Switched to a new branch 'serverfix' ---- -In fact, this is so common that there's even a shortcut for that shortcut. If the branch name you're trying to checkout (a) doesn't exist and (b) exactly matches a name on only one remote, Git will create a tracking branch for you: +事實上,由於太常使用它了,所以還有更簡短的用法;如果你想檢出的分支名稱符合:(a) 尚未存在、(b) 只在一個遠端中完全匹配分支名稱,Git 將會為你產生一個追蹤分支: [source,console] ---- @@ -155,7 +155,7 @@ Branch serverfix set up to track remote branch serverfix from origin. Switched to a new branch 'serverfix' ---- -To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name: +要使用不同於遠端分支名稱的本地分支,只需在第一個版本的命令中替換分支名稱: [source,console] ---- @@ -164,9 +164,9 @@ Branch sf set up to track remote branch serverfix from origin. Switched to a new branch 'sf' ---- -Now, your local branch `sf` will automatically pull from `origin/serverfix`. +現在你的本地分支 `sf` 將會自動從 `origin/serverfix` 拉取資料。 -If you already have a local branch and want to set it to a remote branch you just pulled down, or want to change the upstream branch you're tracking, you can use the `-u` or `--set-upstream-to` option to `git branch` to explicitly set it at any time. +如果你已經有一個本地分支,並且想要它追蹤一個你剛下載的遠端追蹤分支,或者想要改變追蹤上游分支,在任何時候都可以使用 `git branch` 的 `-u` 或 `--set-upstream-to` 選項來明確地設定。 [source,console] ---- @@ -175,14 +175,14 @@ Branch serverfix set up to track remote branch serverfix from origin. ---- [NOTE] -.Upstream shorthand +.上游稱簡 ==== -When you have a tracking branch set up, you can reference its upstream branch with the `@{upstream}` or `@{u}` shorthand. -So if you're on the `master` branch and it's tracking `origin/master`, you can say something like `git merge @{u}` instead of `git merge origin/master` if you wish.(((+++@{u}+++)))(((+++@{upstream}+++))) +當你設定了追蹤分支,你可以用 `@{upstream}` 或 `@{u}` 來表示它的上游分支; +假設你在 `master` 分支而它追蹤了 `origin/master`,如果你想要的話你可以用 `git merge @{u}` 來取代 `git merge origin/master`。(((+++@{u}+++)))(((+++@{upstream}+++))) ==== -If you want to see what tracking branches you have set up, you can use the `-vv` option to `git branch`. -This will list out your local branches with more information including what each branch is tracking and if your local branch is ahead, behind or both. +如果你想知道你設定了哪些追蹤本支,你可以使用 `git branch` 的 `-vv` 選項; +它以更詳盡的資訊列出本地分支,其中包括了它追蹤的分支為何,它們是超前、落後,或者二者都有!? [source,console] ---- @@ -193,33 +193,33 @@ $ git branch -vv testing 5ea463a trying something new ---- -So here we can see that our `iss53` branch is tracking `origin/iss53` and is ``ahead'' by two, meaning that we have two commits locally that are not pushed to the server. -We can also see that our `master` branch is tracking `origin/master` and is up to date. -Next we can see that our `serverfix` branch is tracking the `server-fix-good` branch on our `teamone` server and is ahead by three and behind by one, meaning that there is one commit on the server we haven't merged in yet and three commits locally that we haven't pushed. -Finally we can see that our `testing` branch is not tracking any remote branch. +在這個例子中可以看到分支 `iss53` 正在追蹤 `origin/iss53`,並且它「超前」了二個提交,意思是本地端有二個提交還沒推送到伺服器; +也可以看到 `master` 正在追蹤 `origin/master`,並且已經是最新的; +再下一個可以看到分支 `serverfix` 追蹤的是 `teamone` 的 `server-fix-good` 分支,它超前三個提交,也落後一個提交;意思是伺服端有一個提交還沒有合併進來,同時該分支也有三個提交還沒推送到出去(譯注:其實就是本地端有三個新提交,遠端有一個新提交,二邊的歷史開始分離了)。 +最後,可以看到 `testing` 分支沒有追蹤任何遠端分支。 -It's important to note that these numbers are only since the last time you fetched from each server. -This command does not reach out to the servers, it's telling you about what it has cached from these servers locally. -If you want totally up to date ahead and behind numbers, you'll need to fetch from all your remotes right before running this. -You could do that like this: `git fetch --all; git branch -vv` +必需要注意的是:這些數字是最後一次從每個伺服器獲取資料後所得出的結果, +也就是這個命令並不會連到伺服器去取得相關資料,它只是告訴你上次快取伺服器的狀態後的結果。 +如果你想要完完全全地取得最新的「超前/落後」數字,你需要先將所有伺服器的資料獲取下來,再執這個命令。 +你可以這樣做: `git fetch --all; git branch -vv` -==== Pulling +==== 拉取的用法 (((pulling))) -While the `git fetch` command will fetch down all the changes on the server that you don't have yet, it will not modify your working directory at all. -It will simply get the data for you and let you merge it yourself. -However, there is a command called `git pull` which is essentially a `git fetch` immediately followed by a `git merge` in most cases. -If you have a tracking branch set up as demonstrated in the last section, either by explicitly setting it or by having it created for you by the `clone` or `checkout` commands, `git pull` will look up what server and branch your current branch is tracking, fetch from that server and then try to merge in that remote branch. +`git fetch` 命令會獲取伺服器上你尚未擁有的所有資料,它並不會去改動你工作目錄的內容; +它只是簡單地取得資料,然後讓你自己去合併工作。 +然而,有個命令叫做 `git pull`,在大部分情況下,它實質上等於執行 `git fetch` 後立即執行 `git merge`; +如果你像上一節中所展示的那樣設定追蹤分支——不管是明確地設定它,或者是透過 `clone` 或 `checkout` 命令自動幫你設定——`git pull` 將會查詢目前分支正在追蹤哪一個伺服器上的哪一個分支,然後從那個伺服器獲取資料並合併那個遠端分支的工作。 -Generally it's better to simply use the `fetch` and `merge` commands explicitly as the magic of `git pull` can often be confusing. +一般來說,最好明確地使用 `fetch` 和 `merge` 命令,因為神奇的 `git pull` 常常令人困惑。 [[_delete_branches]] ==== 刪除遠端分支 (((branches, deleting remote))) -Suppose you're done with a remote branch – say you and your collaborators are finished with a feature and have merged it into your remote's `master` branch (or whatever branch your stable codeline is in). -You can delete a remote branch using the `--delete` option to `git push`. -If you want to delete your `serverfix` branch from the server, you run the following: +如果你不再需要某個遠端分支了——例如你和你的同事已經完成了某個特性並把它合併到遠端的 `master` 分支(或合併到任何其它穩定分支裡); +你可以使用 `git push` 的 `--delete` 選項刪除那個遠端分支; +例如想刪除伺服器上的 `serverfix` 分支,執行下面的命令: [source,console] ---- @@ -228,5 +228,5 @@ To https://github.com/schacon/simplegit - [deleted] serverfix ---- -Basically all this does is remove the pointer from the server. -The Git server will generally keep the data there for a while until a garbage collection runs, so if it was accidentally deleted, it's often easy to recover. +基本上,這只是移除了伺服器上的分支指標而已; +Git 伺服器基本上會保留資料一段時間(直到執行垃圾回收),所以如果它是不小心被刪除的,還可以很容易地還原回去。 diff --git a/status.json b/status.json index d73a26c..11be582 100644 --- a/status.json +++ b/status.json @@ -29,7 +29,7 @@ "sections/branch-management.asc": 100, "sections/nutshell.asc": 100, "sections/rebasing.asc": 1, - "sections/remote-branches.asc": 1, + "sections/remote-branches.asc": 100, "sections/workflows.asc": 1 }, "04-git-server": { From 9aa18c393124e5e9d1cb12604909e7243d1bfe00 Mon Sep 17 00:00:00 2001 From: Yue Lin Ho Date: Sat, 30 Apr 2016 02:09:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=82=BA=20Git=20=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=92=8C=E8=A1=93=E8=A9=9E=E5=8A=A0=E4=B8=8A=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E9=99=84=E8=A8=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sections/remote-branches.asc | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/book/03-git-branching/sections/remote-branches.asc b/book/03-git-branching/sections/remote-branches.asc index 535c8c5..c4eecce 100644 --- a/book/03-git-branching/sections/remote-branches.asc +++ b/book/03-git-branching/sections/remote-branches.asc @@ -2,9 +2,9 @@ === 遠端分支 (((branches, remote)))(((references, remote))) -遠端參照是位於遠端版本庫上的參照,包括分支、標籤等等; +遠端參照(references)是位於遠端版本庫上的參照,包括分支(branch)、標籤(tag)等等; 你可以使用 `git ls-remote [remote]` 明確地列出遠端參照完整的列表,或者使用 `git remote show [remote]` 取得更多遠端分支資訊; -然而,更好的方式是利用「遠端追蹤分支」。 +然而,更好的方式是利用「遠端追蹤分支(remote-tracking branch)」。 遠端追蹤分支用來記錄遠端分支的狀態, 它們是無法移動的本地參照,但是會根據網路通訊的結果而自動移動; @@ -12,7 +12,7 @@ 它們採用 `(遠端)/(分支)` 這樣的形式, 例如,你想看上次與 `origin` 版本庫通訊後,它的 `master` 分支指向哪一個提交,你應該查看 `origin/master` 分支; -如果你和同伴一起修正某個議題,而他先推送 `iss53` 分支到遠端版本庫;雖然在你的本地端可能也有一個 `iss53` 分支,但伺服器上的 `iss53` 分支會跟 `origin/iss53` 指向同一個提交。 +如果你和同伴一起修正某個議題,而他先推送 `iss53` 分支到遠端版本庫;雖然在你的本地端可能也有一個 `iss53` 分支,但伺服器上的 `iss53` 分支會跟 `origin/iss53` 指向同一個提交(commit)。 可能有點令人困惑,所以讓我們直接舉例說明; 假設你的網路有一個 Git 伺服器位於 `git.ourcompany.com`, @@ -30,14 +30,14 @@ Git 也會建立屬於你自己的 `master` 本地分支,同樣地,它也指 .克隆後,伺服器和本地端的版本庫 image::images/remote-branches-1.png[克隆後,伺服器和本地端的版本庫。] -如果你在本地分支 `master` 做了一些工作,與此同時,有人推送到 `git.ourcompany.com` 而更新了伺服器上的 `master` 分支,這會讓你的提交歷史朝著不同方向發展; +如果你在本地分支 `master` 做了一些工作,與此同時,有人推送(push)到 `git.ourcompany.com` 而更新了伺服器上的 `master` 分支,這會讓你的提交歷史朝著不同方向發展; 不過只要你不和伺服器連絡,你的 `origin/master` 指標並不會移動。 .本地和遠端的歷史分離開來 image::images/remote-branches-2.png[本地和遠端的歷史分離開來。] 執行 `git fetch origin` 可以同步遠端伺服器上的資料到本地, -該命令首先尋找 `origin` 是哪個伺服器(本例是 `git.ourcompany.com`),從上面獲取你尚未擁有的資料,更新你本地的資料庫,然後把 `origin/master` 指標同步到最新的位置。 +該命令首先尋找 `origin` 是哪個伺服器(本例是 `git.ourcompany.com`),從上面獲取(fetch)你尚未擁有的資料,更新你本地的資料庫,然後把 `origin/master` 指標同步到最新的位置。 .`git fetch` 會更新你的遠端參照 image::images/remote-branches-3.png[`git fetch` 會更新你的遠端參照。] @@ -62,7 +62,7 @@ image::images/remote-branches-5.png[遠端追蹤分支 `teamone/master`。] (((pushing))) 當你想跟世界分享某個分支,你需要把它推送到一個你擁有寫入權限的遠端版本庫; 你的本地分支並不會自動同步到遠端上——你必需明確地推送你想分享的分支; -透過這種方式,你可以將無意分享的分支保留下來做為私用分支,而只推送需要協同工作的主題分支。 +透過這種方式,你可以將無意分享的分支保留下來做為私用分支,而只推送需要協同工作的主題(topic)分支。 如果你有個叫做 `serverfix` 的分支需要和其他人一起開發, 執行 `git push <遠端> <分支>`:(((git commands, push))) @@ -89,10 +89,10 @@ Git 會把 `serverfix` 分支名稱自動地擴展為 `refs/heads/serverfix:refs [NOTE] .不想每次都輸入密碼 ==== -如果你正在使用 HTTPS URL 推送資料,Git 伺服器為了核對身份會詢問你的帳號和密碼; +如果你正在使用 HTTPS URL 推送資料,Git 伺服器為了核對身份(authentication)會詢問你的帳號和密碼; 預設情況它會在終端提示你輸入相關資訊,這樣伺服器才能分辨你是否有推送權限。 -如果你不想每次推送時都輸入它們,你可以設置「證書快取」; +如果你不想每次推送時都輸入它們,你可以設置「證書快取(credential cache)」; 最簡單的方式是執行 `git config --global credential.helper cache` 將它保留記憶體幾分鐘。 詳見 <<_credential_caching>> 以取得各種可使用的、詳細的證書快取方式。 @@ -130,7 +130,7 @@ Switched to a new branch 'serverfix' ==== 追蹤分支 (((branches, tracking)))(((branches, upstream))) -從遠端追蹤分支身上檢出的本地分支會自動升級為「追蹤分支」(它所追蹤的分支則稱為「上游分支」), +從遠端追蹤分支身上檢出的本地分支會自動升級為「追蹤分支(tracking branch)」(它所追蹤的分支則稱為「上游分支(upstream branch)」), 追蹤分支是一種和某個遠端分支有直接聯繫的本地分支; 如果你切換到追蹤分支並執行 `git pull`,Git 會自動分辨要從哪一個伺服器獲取資料,然後自動辨別要合併哪一個分支進來(譯註:就是合併上游分支)。 @@ -164,7 +164,7 @@ Branch sf set up to track remote branch serverfix from origin. Switched to a new branch 'sf' ---- -現在你的本地分支 `sf` 將會自動從 `origin/serverfix` 拉取資料。 +現在你的本地分支 `sf` 將會自動從 `origin/serverfix` 拉取(pull)資料。 如果你已經有一個本地分支,並且想要它追蹤一個你剛下載的遠端追蹤分支,或者想要改變追蹤上游分支,在任何時候都可以使用 `git branch` 的 `-u` 或 `--set-upstream-to` 選項來明確地設定。 @@ -182,7 +182,7 @@ Branch serverfix set up to track remote branch serverfix from origin. ==== 如果你想知道你設定了哪些追蹤本支,你可以使用 `git branch` 的 `-vv` 選項; -它以更詳盡的資訊列出本地分支,其中包括了它追蹤的分支為何,它們是超前、落後,或者二者都有!? +它以更詳盡的資訊列出本地分支,其中包括了它追蹤的分支為何,它們是超前(ahead)、落後(behind),或者二者都有!? [source,console] ----