环境说明:
OS:CentOS-6.5.mininal (NULL)
GIT:git version 2.8.2
准备工作:
-
安装 EPEL源
1[root@lucia ~]# su xiaolu 2[xiaolu@lucia root]$ cd /etc/yum.repos.d/ 3[xiaolu@lucia yum.repos.d]$ sudo yum -y install wget 4[xiaolu@lucia yum.repos.d]$ sudo mv CentOS-Base.repo CentOS-Base.repo.bak 5[xiaolu@lucia yum.repos.d]$ sudo wget -O CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2 6 # wget -O --output-document=FILE 指定下载目录和文件名 7[xiaolu@lucia yum.repos.d]$ yum makecache
根据CentOS的版本下载不同的镜像 ( 使用的是国内的EPEL源-科大源)
附-科大源:https://lug.ustc.edu.cn/wiki/mirrors/help/centos
-
时间校准
1[xiaolu@lucia yum.repos.d]$ cd /tmp 2[xiaolu@lucia tmp]$ sudo yum -y install ntpdate.x86_64 3[xiaolu@lucia tmp]$ sudo ntpdate 0.pool.ntp.org 4 1 Apr 16:40:49 ntpdate[7329]: no server suitable for synchronization found 5--------------------------------------------------------------------------------- 6[xiaolu@lucia tmp]$ sudo yum -y install rdate.x86_64 7[xiaolu@lucia tmp]$ sudo rdate -s time.nist.gov 8[xiaolu@lucia tmp]$ date 9Sun May 1 23:17:19 CST 2016
注:ntpdate校准报错选择rdate(很可能是防火墙封锁了udp的123端口, 如果关闭的防火墙问题依旧, 很可能是上层路由的设置有问题, 如果这种情况, 我们就只能通过tcp来更新时间)
安装Git( 源代码安装)
Step 1: 安装所需的依赖包
-
源代码编译GIT之前,确保系统安装了所需的包或者通过以下命令来安装它
1[xiaolu@lucia tmp]$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker package -y 2[xiaolu@lucia tmp]$ sudo yum -y install gcc (下载 编译器 )
Step 2:下载并编译GIT源代码
-
从 git-scm 下载最新Git源代码或者简单的使用以下载命令下载Git 2.8.2
1[xiaolu@lucia tmp]$ sudo wget -c https://www.kernel.org/pub/software/scm/git/git-2.8.2.tar.gz 2[xiaolu@lucia tmp]$ tar -zxvf git-2.8.2.tar.gz 3[xiaolu@lucia tmp]$ cd git-2.8.2 4[xiaolu@lucia git-2.8.2]$ make prefix=/usr/local/git all 5[xiaolu@lucia git-2.8.2]$ sudo make prefix=/usr/local/git install 6[xiaolu@lucia git-2.8.2]$ su root 7[root@lucia git-2.8.2]# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc # 设置环境变量 8[root@lucia git-2.8.2]# source /etc/bashrc
Step 3:核实GIT 版本
-
完成以上步骤后,使用以下命令检查GIT版本
1[xiaolu@lucia git-2.8.2]$ git --version 2git version 2.8.2
Step 4:命令补全
-
Linux的shell环境通过bash-completion软件包提供命令补齐功能,在录入命令参数时按一次或两次TAB键可实现参数的自动补齐或提示
1[xiaolu@lucia git-2.8.2]$ sudo cp contrib/completion/git-completion.bash /etc/bash_completion.d/ 2 #将Git源码包中的命令补全脚本肤质到bash-completion对应的目录中 3 4[xiaolu@lucia git-2.8.2]$ . /etc/bash_completion.d/git-completion.bash 5 #重新加载自动补齐脚本,使之在当前的shell中生效 -
为了能够在终端开启时自动加载脚本,需要修改/etc/profile文件和~/.bashrc文件
1[root@lucia git-2.8.2]# sudo cat >> ~/.bashrc <<EOF 2> if [ -f /etc/bash_completion.d/git-completion.bash ]; then 3> . /etc/bash_completion.d/git-completion.bash 4> fi 5> EOF 6[xiaolu@lucia git-2.8.2]$ su root 7[root@lucia git-2.8.2]# sudo cat >> /etc/profile <<EOF 8> if [ -f /etc/bash_completion.d/git-completion.bash ]; then 9> . /etc/bash_completion.d/git-completion.bash 10> fi 11> EOF
附1:中文支持
- 相关说明:
GIT可以在提交说明中使用中文,但是需要对Git进行配置但对于用中文来命名文件、目录和引用,前提是使用UTF-8 字符集的环境下
- UTF8字符集:
1、在提交时,可以在提交说明中输入中文
2、显示提交历史,能够正常显示提交说明中的中文字符
3、可以添加名称为中文的文件,并可以在同样使用UTF-8字符集的Linux环境中克隆和检出
4、可以创建带有中文字符的里程碑名称
BUT!!!
❀ 在默认设置下,中文文件名在工作区状态输出、查看历史更改概要,以及在补丁文件中,文件名中的中文不能正确的显示,而是显示为八进制的字符编码,如下
1[xiaolu@lucia rs-project]$ git status -s 2?? "\346\265\213\350\257\225.txt" 3[xiaolu@lucia rs-project]$ printf "\346\265\213\350\257\225.txt\n" 4测试.txt
❀ **解决方法:**通过将Git配置变量 core.quotepath 设置为 false
1[xiaolu@lucia rs-project]$ git config --global core.quotepath false[xiaolu@lucia rs-project]$ 2[xiaolu@lucia rs-project]$ git status -s 3?? 测试.txt
附2:相关问题
make prefix=/usr/local/git all 报错
目前我碰到的报错有两种:
-
时间没有校准(看见 in the future 就是时间没有校准,校准后重新make)
1ake[1]: Warning: File `Makefile' has modification time 2.5e+06 s in the future 2/usr/bin/perl Makefile.PL PREFIX='/usr/local' INSTALL_BASE='' --localedir='/usr/local/share/locale' 3Writing perl.mak for Git 4make[1]: warning: Clock skew detected. Your build may be incomplete. 5 GEN git-add--interactive 6make[1]: Warning: File `Makefile' has modification time 2.5e+06 s in the future 7Writing perl.mak for Git 8make[2]: Warning: File `Makefile.PL' has modification time 2.5e+06 s in the future 9Writing perl.mak for Git 10make[2]: *** [perl.mak] Error 1 11make[1]: *** [instlibdir] Error 2 12make: *** [git-add--interactive] Error 2
2. 第二种报依赖包错误,导致make失败
本文OS是纯净版,实际上真正OS环境下许多依赖包已经安装,且通过yum仓库安装的版本都较老,换yum源后将提示的相关依赖包卸载(rpm -e),然后重新yum安装一下
#-------------------------------------------------------------------------------------------------------------------#

Lucia 2016/05
#-------------------------------------------------------------------------------------------------------------------#
附3:记住GIT账户和密码(2016/09新增)
1# 以这种格式 https://{username}:{password}@git.oschina.net写入隐藏文件.git-credentials 2[xiaolu@lucia ~]$ echo https://{luciaxxx@163.com}:{xxxxxx}@git.oschina.net >> .git-credentials 3[xiaolu@lucia ~]$ cat .git-credentials 4https://{luciaxxx@163.com}:{xxxxxx}@git.oschina.net 5 6# 运行git配置命令 7[xiaolu@lucia ~]$ git config --global credential.helper store 8[xiaolu@lucia ~]$ cat .gitconfig 9[credential] 10 helper = store 11 12# 第一次拉取仓库时仍需要输入用户名及密码进行验证 13[xiaolu@lucia ~]$ git clone https://git.oschina.net/lucia-moore/Auto-Install.git 14Cloning into 'Auto-Install'... 15Username for 'https://git.oschina.net': luciaxxx@163.com 16Password for 'https://luciaxxx@163.com@git.oschina.net': 17remote: Counting objects: 3, done. 18remote: Total 3 (delta 0), reused 0 (delta 0) 19Unpacking objects: 100% (3/3), done. 20Checking connectivity... done. 21 22[xiaolu@lucia ~]$ ls 23Auto-Install 24 25#此时查看文件.git-credentials会多出一项,证明配置成功了 26[xiaolu@lucia ~]$ cat .git-credentials 27https://luciaxxx%40163.com:xxxxxx@git.oschina.net 28https://{luciaxxx@163.com}:{xxxxxx}@git.oschina.net 29 30#此时 git pull 就不需要输入用户名和密码直接pull 31[xiaolu@lucia ~]$ cd Auto-Install/ 32[xiaolu@lucia Auto-Install]$ git pull https://git.oschina.net/lucia-moore/Auto-Install.git 33From https://git.oschina.net/lucia-moore/Auto-Install 34 * branch HEAD -> FETCH_HEAD 35Already up-to-date.