cenots 源码安装git 2.7.4

原创 赤水  2016年11月3日 10:38 阅读 3 次
    Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。    
    下面教程基于centos 6.5,git-2.7.4配置安装

1、安装git

yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel 
cd /usr/local/src ; wget https://www.kernel.org/pub/software/scm/git/git-2.7.4.tar.gz --no-check-certificate
tar zxvf git-2.7.4.tar.gz ; cd git-2.7.4
make prefix=/usr/local/git all &&  make prefix=/usr/local/git install
ln -s /usr/local/git/bin/* /usr/bin/
2、查看版本号:
[root@gitserver git-2.7.4]# git --version
git version 2.7.4
3、创建git用户
[root@gitserver ~]# useradd git
4、在git用户家目录下安装gitolite
[root@gitserver ~]# su - git 
[git@gitserver ~]$ mkdir bin
[git@gitserver ~]$ git clone https://github.com/sitaramc/gitolite.git 
Cloning into 'gitolite'...
remote: Counting objects: 9307, done.
remote: Total 9307 (delta 0), reused 0 (delta 0), pack-reused 9307
Receiving objects: 100% (9307/9307), 2.93 MiB | 575.00 KiB/s, done.
Resolving deltas: 100% (5756/5756), done.
Checking connectivity... done.

[git@gitserver ~]$ ./gitolite/install --to /home/git/bin/
[git@gitserver ~]$  ls bin/
commands  gitolite  gitolite-shell  lib  syntactic-sugar  triggers  VERSION  VREF
5、生成管理员账户的公钥(此处指定本地root用户为管理员,键入回车使用默认值)
[root@gitserver ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? 
[root@gitserver ~]# cp ~/.ssh/id_rsa.pub /tmp/admin.pub
6、切换回git用户,为gitolite配置管理员
[root@gitserver ~]# su git
[git@gitserver root]$ cd 
[git@gitserver ~]$ bin/gitolite setup -pk /tmp/admin.pub 
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
Initialized empty Git repository in /home/git/repositories/testing.git/
WARNING: /home/git/.ssh missing; creating a new one
    (this is normal on a brand new install)
WARNING: /home/git/.ssh/authorized_keys missing; creating a new one
    (this is normal on a brand new install)
[git@gitserver ~]$ ls
bin  gitolite  projects.list  repositories
7、下载gitolite-admin管理git
[root@gitserver git-2.7.4]# mkdir /git ; cd /git ; git clone git@127.0.0.1:gitolite-admin
Cloning into 'gitolite-admin'...	'
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
RSA key fingerprint is 1c:32:7d:8f:c9:cc:b2:d8:7e:91:de:be:77:78:95:e3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts.
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (6/6), 739 bytes | 0 bytes/s, done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Checking connectivity... done.

8、创建mytest库,创建test用户,为test分配mytest库读+写权限
test用户在自己服务器上生成ssh无密码公钥ssh-keygen,然后将ssh-keygen复制到git所在服务器,最后test用户的ssh-keygen复制到 gitolite-admin/keydir/下
[root@client ~]# scp ~/.ssh/id_rsa.pub 172.16.1.29:/tmp/test.pub
[root@gitserver git]# cp /tmp/test.pub  /git/gitolite-admin/keydir/
[root@gitserver git]# cat /git/gitolite-admin/conf/gitolite.conf	#默认内容
repo gitolite-admin
    RW+     =   admin

repo testing
    RW+     =   @all
下边定义mytest库,并且指定用户权限:
#在gitolite.conf中添加以下内容
@mygroup    = test
repo mytest    
    RW+     = @mygroup
#此处@mygroup是一个组,给mygroup组赋予对mytest这个库的读、写、推送的权限
[root@gitserver git]# cd gitolite-admin/
[root@gitserver gitolite-admin]# git status	#查看git库状态
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   conf/gitolite.conf	#修改文件
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        keydir/test.pub					#新增文件
no changes added to commit (use "git add" and/or "git commit -a")

将有改动的文件添加到git库
[root@gitserver gitolite-admin]# git commit -m "add repo mytest; add user test"
*** Please tell me who you are.
Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@gitserver.(none)')'
配置使用者的用户名和邮箱
[root@gitserver gitolite-admin]# git config --global user.email "postmaster@lssin.com"
[root@gitserver gitolite-admin]# git config --global user.name "blog.lssin.com"
[root@gitserver gitolite-admin]# add repo mytest; add user test		#再重新执行git commit命令
 2 files changed, 4 insertions(+)
 create mode 100644 keydir/test.pub
执行完以上命令后,修改的文件只是提交在本地了,并没有提交到git server中,还需要执行git push命令
[root@gitserver gitolite-admin]# git push	 	#推送到远端的master分支
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 6, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 821 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Initialized empty Git repository in /home/git/repositories/mytest.git/
To git@127.0.0.1:gitolite-admin
   6500d14..86e0580  master -> master


[root@gitserver gitolite-admin]# git config --global push.default simple	#忽略plush警告
9、test用户,下载库,创建测试文件1.txt,并提交到git服务器
[root@client ~]# git clone git@172.16.1.29:/mytest.git
Cloning into 'mytest'...
Address 172.16.1.29 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
10、第一次使用需要表明身份
[root@client ~]# git config --global user.email 'test@lssin.com'
[root@client ~]# git config --global user.name 'test'
11、创建测试文件,push到git服务器
[root@client ~]# echo `date` > 1.t^C
[root@client ~]# cd mytest/
[root@client mytest]# echo `date` > 1.txt
[root@client mytest]# cat 1.txt 
Wed Nov 2 22:18:50 EDT 2016
[root@client mytest]# git add 1.txt 
[root@client mytest]# git commit -m 'add test file 1.txt'
[master (root-commit) 8bfbc7f] add test file 1.txt
 1 file changed, 1 insertion(+)
 create mode 100644 1.txt
 
[root@client mytest]# git push origin master	
Address 172.16.1.29 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Counting objects: 3, done.
Writing objects: 100% (3/3), 233 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@172.16.1.29:/mytest.git
 * [new branch]      master -> master

 

 


本文地址: https://blog.lssin.com/readblog/122.html
版权声明:本文为原创文章,版权归  赤水 所有,欢迎分享本文,转载请保留出处!

发表评论


表情