Linux安装Git服务

[root@testgit rpmlib]# pwd
/opt/rpmlib
[root@testgit rpmlib]# ls
asciidoc-8.6.9-1.el6.rfx.noarch.rpm   gettext-devel-0.17-16.el6.x86_64.rpm
autoconf-2.63-5.1.el6.noarch.rpm      libiconv-1.14.tar.gz
curl-devel-7.13.1-3.x86_64.rpm        openssl-devel-1.0.1e-42.el6.x86_64.rpm
docbook2X-0.8.8-2.1.x86_64.rpm        xmlto-0.0.18-4.x86_64.rpm
expat-devel-2.0.1-9.1.el6.x86_64.rpm  zlib-devel-1.2.3-29.el6.x86_64.rpm
[root@testgit rpmlib]# rpm -q curl-devel
[root@testgit rpmlib]# rpm -ivh curl-devel-7.13.1-3.x86_64.rpm --nodeps
[root@testgit rpmlib]# rpm -q expat-devel
[root@testgit rpmlib]# rpm -ivh expat-devel-2.0.1-9.1.el6.x86_64.rpm --nodeps
[root@testgit rpmlib]# rpm -q gettext-devel
[root@testgit rpmlib]# rpm -ivh gettext-devel-0.17-16.el6.x86_64.rpm --nodeps
[root@testgit rpmlib]# rpm -q openssl-devel
[root@testgit rpmlib]# rpm -ivh openssl-devel-1.0.1e-42.el6.x86_64.rpm --nodeps
[root@testgit rpmlib]# rpm -q zlib-devel
[root@testgit rpmlib]# rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm --nodeps
[root@testgit rpmlib]# rpm -q perl-devel
perl-devel-5.10.1-119.el6_1.1.x86_64

[root@testgit rpmlib]# rpm -q asciidoc
[root@testgit rpmlib]# rpm -ivh asciidoc-8.6.9-1.el6.rfx.noarch.rpm --nodeps
[root@testgit rpmlib]# rpm -q autoconf
[root@testgit rpmlib]# rpm -ivh autoconf-2.63-5.1.el6.noarch.rpm --nodeps
[root@testgit rpmlib]# rpm -q docbook2X
[root@testgit rpmlib]# rpm -ivh docbook2X-0.8.8-2.1.x86_64.rpm --nodeps
[root@testgit rpmlib]# rpm -q xmlto
[root@testgit rpmlib]# rpm -ivh xmlto-0.0.18-4.x86_64.rpm --nodeps


要是没有gcc的相关编译器不能进行源码安装,下面是CentOS6上需要安装的gcc等相关rpm包:
cloog-ppl-0.15.7-1.2.el6.x86_64.rpm
cpp-4.4.6-4.el6.x86_64.rpm
gcc-4.4.7-16.el6.x86_64.rpm
gcc-c++-4.4.7-16.el6.x86_64.rpm
glibc-devel-2.12-1.166.el6.x86_64.rpm
glibc-headers-2.12-1.80.el6.x86_64.rpm
kernel-headers-2.6.32-279.el6.x86_64.rpm
libstdc++-devel-4.4.6-4.el6.x86_64.rpm
mpfr-2.4.1-6.el6.x86_64.rpm
ppl-0.10.2-11.el6.x86_64.rpm



[root@testgit opt]# tar -zxvf git-2.7.0.tar.gz
[root@testgit opt]# cd git-2.7.0
[root@testgit git-2.7.0]# autoconf
[root@testgit git-2.7.0]# ./configure --prefix=/usr/local
[root@testgit git-2.7.0]# make
[root@testgit git-2.7.0]# make install
[root@testgit git-2.7.0]# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib          --这一行是后加的,不加这一行在输入git --version的时候会报错
[root@testgit git-2.7.0]# /sbin/ldconfig
[root@testgit git-2.7.0]# git --version
git version 2.7.0



----------------------------------------------------------------------------------



下面是Git基本操作:

RPM包下载地址: http://rpm.pbone.net/index.php3/stat/21/year/2005/month/05/day/03
http://pkgs.org/download/
http://rpmfind.net/linux/rpm2html/search.php

如果你想从源码安装 Git,需要安装 Git 依赖的库:curl、zlib、openssl、expat,还有libiconv。 如果你的系统上有 yum (如 Fedora)或者 apt-get(如基于 Debian 的系统),可以使用以下命令之一来安装最小化的依赖包来编译和安装 Git 的二进制版:

  $ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
  $ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
为了能够添加更多格式的文档(如 doc, html, info),你需要安装以下的依赖包:

  $ sudo yum install asciidoc xmlto docbook2x
  $ sudo apt-get install asciidoc xmlto docbook2x
当你安装好所有的必要依赖,你可以继续从几个地方来取得最新发布版本的tar包。 你可以从Kernel.org网站获取,网址为https://www.kernel.org/pub/software/scm/git,或从 GitHub 网站上的镜像来获得,网址为 https://github.com/git/git/releases。 通常在 GitHub 上的是最新版本,但 kernel.org 上包含有文件下载签名,如果你想验证下载正确性的话会用到。

rpm -q gcc gcc-c++ glibc glibc-common glibc-devel
rpm -q libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
rpm -ivh gettext-devel-0.17-16.el6.x86_64.rpm --nodeps
rpm -ivh libiconv-1.14-3.el6.x86_64.rpm --nodeps

tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local     (或者#./configure --prefix=/usr/local/libiconv)
make
make install


接着,编译并安装:

  $ tar -zxf git-2.7.0.tar.gz
  $ cd git-2.7.0
  $ make configure
  $ ./configure --prefix=/usr
  $ make all doc info
  $ sudo make install install-doc install-html install-info
完成后,你可以使用 Git 来获取 Git 的升级:

  $ git clone git://git.kernel.org/pub/scm/git/git.git



Red Hat Enterprise Linux 6.4源码安装Git服务器步骤如下:
rpm -q curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel
tar -zxf git-2.7.0.tar.gz
cd git-2.7.0
autoconf
./configure 或者 ./configure --prefix=/usr/local 或者 ./configure --prefix=/usr/local/git/
make
make install
[root@testagent lib]# pwd
/usr/local/lib
[root@testagent lib]# ls
charset.alias  libcharset.so        libiconv.la    libiconv.so.2.5.1
libcharset.a   libcharset.so.1      libiconv.so    preloadable_libiconv.so
libcharset.la  libcharset.so.1.0.0  libiconv.so.2
[root@testagent /]# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib          --这一行是后加的,不加这一行在输入git --version的时候会报错

[root@testagent /]# /sbin/ldconfig
[root@testagent git-2.7.0]# git --version
git version 2.7.0
[root@testagent git-2.7.0]# cd /usr/local/bin
[root@testagent bin]# pwd
/usr/local/bin
[root@testagent bin]# ls
git            gitk              git-shell           git-upload-pack
git-cvsserver  git-receive-pack  git-upload-archive  iconv


可以把Git服务加入到环境变量里:
[root@testagent /]# vi /etc/profile
export GIT_HOME=/usr/local/git/
export PATH=$PATH:$GIT_HOME/bin


创建Git仓库步骤如下:
[root@testagent git-2.7.0]# cd /
[root@testagent /]# useradd git
[root@testagent /]# passwd git
Changing password for user git.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@testagent /]# su - git
[git@testagent ~]$ ls
[git@testagent ~]$ mkdir mygitproject
[git@testagent ~]$ ls
mygitproject
[git@testagent ~]$ cd mygitproject/
[git@testagent mygitproject]$ ls
[git@testagent mygitproject]$ git --bare init
Initialized empty Git repository in /home/git/mygitproject/
[git@testagent mygitproject]$ ls
branches  config  description  HEAD  hooks  info  objects  refs
[git@testagent mygitproject]$

https://git-for-windows.github.io/        下载mysysgit
http://tortoisegit.org/download/          下载TortoiseGit

先要clone一个.git文件夹到本地Windows机器

http://bbs.csdn.net/topics/390902529/
origin
[email protected]:mygitproject
http://blog.csdn.net/forever_wind/article/details/37506389
http://www.cnblogs.com/wang_yb/p/3867221.html



由于git默认拒绝了push操作,需要进行设置,修改.git/config添加如下代码:
[receive]
denyCurrentBranch = ignore


[git@testagent mygitproject]$ pwd
/home/git/mygitproject
branches  config  description  HEAD  hooks  info  objects  refs
[git@testagent mygitproject]$ vi config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
[receive]
denyCurrentBranch = ignore
[git@testagent mygitproject]$ cat config


[git@testagent ~]$ pwd
/home/git
[git@testagent ~]$ git clone mygitproject git1
[git@testagent ~]$ git clone mygitproject git2
目前git branch是空的。我们提交一点东西建立master分支。
[git@testagent ~]$ cd git1
[git@testagent git1]$ pwd
/home/git/git1
[git@testagent git1]$ touch a.txt
[git@testagent git1]$ git add .
[git@testagent git1]$ git commit -m "init"
[git@testagent git1]$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 199 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /home/git/mygitproject/
* [new branch]      master -> master
[git@testagent git1]$ git branch -a
* master
  remotes/origin/master


[git@testagent git2]$ pwd
/home/git/git2
[git@testagent git2]$ git pull origin
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/git/mygitproject
* [new branch]      master     -> origin/master
[git@testagent git2]$ ls
a.txt

[git@testagent heads]$ pwd
/home/git/mygitproject/refs/heads
[git@testagent heads]$ ls
master

[git@testagent git1]$ git commit -am "a.txt add : git1 user add nihao"
[master 4356801] a.txt add : git1 user add nihao
1 file changed, 2 insertions(+), 1 deletion(-)

本地分支提交到远程分支的命令格式: git push origin 本地分支:远程分支
[git@testagent git1]$ git push origin master:master
Counting objects: 3, done.
Writing objects: 100% (3/3), 277 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /home/git/server
   9e4111e..4356801  master -> master

Windows主机上修改了某个文件后必须在TortoiseGit中做两步操作才能提交到远程仓库:
第一步: Git提交(C)-> "master"...   --这一步是提交到本地仓库, 相当于git commit -am "description message"
第二步: 推送...                    --这一步是提交到远程仓库, 相当于git push origin master:master

【注】: Git跟Svn不同,Git必须先提交到本地仓库再提交到远程仓库。

从远程仓库拉取文件到本地的命令格式: git pull origin master:master
[git@testagent git1]$ git pull origin master:master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/git/server
   4356801..a69dceb  master     -> master
   4356801..a69dceb  master     -> origin/master
warning: fetch updated the current branch head.
fast-forwarding your working tree from
commit 4356801baf0cc3d83e29145384374cb4b6e30360.
Already up-to-date.
[git@testagent git1]$

删除仓库文件命令如下:
git add -u
git commit -m "delete test"
git push


Git服务器权限管理工具:
gitlab gitolite gitosis

你可能感兴趣的:(linux,centos,git)