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 建库

posted on 2012-01-05 18:15  IT老友  阅读(12081)  评论(0编辑  收藏  举报

导航