天天看點

Git, Gerrit, Hudson (1) -- 安裝配置用戶端

1. 安裝git用戶端

(1)MsysGIT

MsysGIT是指令行版本工具,它是其它工具能運作的基礎。下載下傳 Git-1.7.3.1-preview20101002.exe 。

下載下傳成功後安裝,将安裝 git 和一個友善的 bash shell 工具。

注意,安裝時選擇:

"Run Git from the Windows Command Prompt"

"Checkout as-is, commit as-is" 

(2)Tortoise

TortoiseGIT 是一個 git 版的 Tortoise 工具。可以和 TortoiseSVN 一起使用。

下載下傳 TortoiseGIT 1.6.5.0 。

注意: 安裝時會讓你選擇使用 PAgent ,還是 OpenSSH ,強烈推薦使用 OpenSSH 。

(3)EGit

EGit 是 Eclipse 使用的 git 插件,在 Eclipse Marketplace (選擇 Help -> Eclipse Marketplace )中可以現在安裝。

2. 生成密鑰對

安裝好以上工具後,第一件要做的事是生成密鑰對,以供 server 驗證你的身份資訊。

(1) 打開 "Git bash" (安裝完 MsysGIT 後就有 );

(2) 輸入: ssh-keygen

(3) 使用預設路徑(直接回車 )

(4) 輸入密碼 (該步驟可選,直接回車即沒有密碼 )

(5) 記住你的密鑰對生成的位置 (預設在 H 盤 )

3. 配置 Tortoise 和 EGit

生成的密鑰對可用于 Tortoise 和 EGit。 需要将它們拷貝到以下目錄:

C:\Documents and Settings\<username>\ssh (EGit 使用該路徑 )

C:\Documents and Settings\<username>\.ssh ( Tortoise 使用該路徑 )

Windows 下不能直接建立以 "." 開頭的檔案,需要使用 cmd 工具。

在 Eclipse 中選擇以下路徑:

Window -> Preferences -> General -> Network Connections -> SSH2 -> Add Private Key

加入私鑰,公鑰檔案 "id_rsa.pub" 不必加入。

4. 配置 GIT

使用以下指令建立 git 配置檔案:

git config --global user.name <your_user_name>
git config --global user.email <your_email>
git config --global core.autocrlf input
git config --global core.filemode false
git config --global core.diff auto
git config --global core.status auto
git config --global core.branch auto      

以上指令會在 H 盤建立一個 ".gitconfig" 檔案。如果要使用 Tortoise, 還需要把這個檔案拷貝到:

C:\Documents and Settings\<username>directory

EGit 會自動使用 H 盤上的配置檔案。

使用以下指令可以檢視具體的配置資訊:

git config --global -l      

5. 登入 Gerrit

(1)通路 Gerrit 伺服器頁面 http://<Gerrit_host_name>:<Port> (這個應該由管理者配置好的 )

(2)點選 "Sign In"

(3)輸入使用者名 (例如: 域名\Windows使用者名 )

(4)填入你的公鑰,打開 id_rsa.pub 檔案,粘貼入頁面上的文本域,點選 "Add" 。

6. 測試 ssh 連接配接

(1)打開 GIT bash

(2)輸入:

ssh <username>@<Gerrit_host_name> -p 29418      

回車後會出現認證提示。

7.建立登入配置檔案

如果要簡化登入指令,可以在 H 盤和 "Documents and Settings" 下的 .ssh 目錄下建立 "config" 檔案( 無字尾名 )。輸入以下内容:

Host review gerrit
  Hostname <Gerrit_host_name>
  Port 29418
  User <username>      

現在可以使用以下指令來連接配接伺服器:

ssh review
或者
ssh gerrit      

也可以給 Tortoise,Eclipse 和 MsysGIT 進行這種配置 (如果需要的話)。

8.設定環境

如果需要在 git 指令行啟動時加載自定義的預設配置,可以在 H 盤下建立 ".bash_profile" 檔案,輸入需要的指令,例如:

export GIT_EDITOR=notepad
cd /c/GIT      

以上配置将 notepad 設為預設編輯器,并且切換目錄至 /c/GIT。