Linux下TortoiseGit 配置管理環境搭建


RedHat Git服務器安裝
安裝前准備
需要安裝zlib,curl,rsync,libcrypto.
可以用# rpm -qa|grep zlib 命令檢查
安裝配置
1. 下載git-1.7.8.rc3.tar.gz
2. 解壓后執行
   #configure --prefix=/usr/local/git
   #make
   #make install
3. 將/usr/local/git/libexec/git-core 和/usr/local/git/bin加入PATH
4.git軟件安裝完成后,該 創建git庫
a)#cd repos-home
 #git-init-db
如果是創建bare目錄,目錄名字通常以.git結尾
 #git --bare init
b)跟蹤文件
 git-add 和 git-update-index
c)提交文件
 $ git-commit -a -m "new day for git"


Windows Git客戶端安裝
安裝
由於tortoiseGit是對msysgit的封裝,所以在安裝tortoiseGit前需要安裝msysgit
http://code.google.com/p/msysgit/下載Git-1.7.4-preview20110204.exe后安裝
http://code.google.com/p/tortoisegit下載tortoisegit.msi后安裝
選擇tortoisePlink用於與git服務器的ssh連接,
配置ssh互通
Git客戶端與服務器端代碼上傳必須用ssh協議,所以需要配置兩台機器支持ssh密鑰直接登陸。
a) 在Linux服務器上建立一個git帳號,用於多人使用。
/home/git 下建立.ssh目錄(注意,是.ssh。。有個點!)
chmod 700 -R .ssh

b) 在Windows中使用c:\program files\git\bin\ssh-keygen -t rsa 生成密匙和公匙,即id_rsa 和 id_rsa.pub
c) 將id_rsa.pub 拷貝到Linux服務器的/home/git/.ssh/中,添加到authorized_keys文件后,如果沒有這個文件可以如下創建:
#cat id_rsa.pub > authorized_keys
將authorized_keys 權限改為600
修改/etc/ssh/sshd_config
RSAAuthentication yes            #開啟RSA認證功能
PubkeyAuthentication yes      #開啟公匙認證
AuthorizedKeysFile      .ssh/authorized_keys
d) 測試是否可以不用口令登陸Linux服務器
c:\program files\git\bin\ssh -i id_rsa root@192.168.6.131 echo $PATH

e) 轉換公鑰格式,以便TortoisePlink.exe 可用

執行C:\Program Files\TortoiseGit\bin\puttygen.exe, 選load按鈕加載id_rsa后,保存

執行TortoisePlink.exe -i c:\id_pri.ppk root@192.168.6.131 echo $path 測試不需要口令登錄

從服務器clone版本庫

右鍵點擊目錄,選擇git-clone,

從服務器端clone版本庫后,即可在工作目錄開始工作。

常見問題:

Q: 在clone時出現以下問題bash: git-upload-pack Command not found
A: 該問題是由於服務器端環境變量PATH無法找到git-upload-pack程序。
    與ssh交互登錄不同,無密碼登錄后.bash_profile中的環境變量沒有生效,因此需要采取以下步驟。

   修改Linux上sshd進程的配置文件(一般為/etc/ssh/sshd_config,請用sshd -V確認)。增加如下配置行:
PermitUserEnvironment yes
此外在.ssh目錄下編輯生成文件environment,內容可以考慮和.bash_profile相同,但不需要執行export
之后重啟采集機上的sshd守護進程。Kill -HUP sshd

   現在再用c:\program files\git\bin\ssh -i id_rsa root@192.168.6.131 echo $PATH確認PATH環境變量是否生效。

常用命令
初始化git數據庫
$ git-init-db
添加文件
$ git-add hello.c
查看修改、提交記錄
$ git-log
創建分支
$ git-branch roredu
查看分支
$ git-branch
* master
roredu
切換工作分支
$ git-checkout roredu
Switched to branch "roredu"
$ git-branch
master
* roredu
提交到當前工作分支並書寫標記。
$ git-commit -a
創建xux分支對於master的補丁文件。
$ git-format-patch master roredu
配置開發者自己的簽名和email。
$ git-config --global user.name "roredu"
$ git-config --global user.email "roredu@gmail.com"
修改文件名
$ git-mv roredu.c helight.c
刪除文件
$ git-rm roredu.c
合並:
切換到master,再選擇Merge

如何clone版本庫

cd /slview

git clone root@localhost:/slview/git-repos git-workhome

錯誤:

bash: git-upload-pack: command not found
fatal: The remote end hung up unexpectedly

解答:

[root@localhost code]# ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack 

 錯誤:

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match

解決:

用git --bare init 建庫


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM