linux git源代码安装,Linux源代码安装Git及其他附录

环境说明:

OS:CentOS-6.5.mininal  (NULL)

GIT:git version 2.8.2

准备工作:

安装 EPEL源 [root@lucia ~]# su xiaolu

[xiaolu@lucia root]$ cd /etc/yum.repos.d/

[xiaolu@lucia yum.repos.d]$ sudo yum -y install wget

[xiaolu@lucia yum.repos.d]$ sudo mv CentOS-Base.repo CentOS-Base.repo.bak

[xiaolu@lucia yum.repos.d]$ sudo wget -O CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2

# wget -O  --output-document=FILE  指定下载目录和文件名

[xiaolu@lucia yum.repos.d]$ yum makecache

根据CentOS的版本下载不同的镜像   (  使用的是国内的EPEL源-科大源)

时间校准 [xiaolu@lucia yum.repos.d]$ cd /tmp

[xiaolu@lucia tmp]$ sudo yum -y install ntpdate.x86_64

[xiaolu@lucia tmp]$ sudo ntpdate 0.pool.ntp.org

1 Apr 16:40:49 ntpdate[7329]: no server suitable for synchronization found

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

[xiaolu@lucia tmp]$ sudo yum -y install rdate.x86_64

[xiaolu@lucia tmp]$ sudo rdate -s time.nist.gov

[xiaolu@lucia tmp]$ date

Sun May  1 23:17:19 CST 2016

注:ntpdate校准报错选择rdate(很可能是防火墙封锁了udp的123端口, 如果关闭的防火墙问题依旧, 很可能是上层路由的设置有问题, 如果这种情况, 我们就只能通过tcp来更新时间)

安装Git(源代码安装)

Step 1: 安装所需的依赖包

源代码编译GIT之前,确保系统安装了所需的包或者通过以下命令来安装它 [xiaolu@lucia tmp]$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker package -y

[xiaolu@lucia tmp]$ sudo yum -y install gcc  (下载 编译器 )

‍‍  Step 2:下载并编译GIT源代码 ‍‍

从 git-scm 下载最新Git源代码或者简单的使用以下载命令下载Git 2.8.2 [xiaolu@lucia tmp]$ sudo wget -c https://www.kernel.org/pub/software/scm/git/git-2.8.2.tar.gz

[xiaolu@lucia tmp]$ tar -zxvf git-2.8.2.tar.gz

[xiaolu@lucia tmp]$ cd git-2.8.2

[xiaolu@lucia git-2.8.2]$ make prefix=/usr/local/git all

[xiaolu@lucia git-2.8.2]$ sudo make prefix=/usr/local/git install

[xiaolu@lucia git-2.8.2]$ su root

[root@lucia git-2.8.2]# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc   # 设置环境变量

[root@lucia git-2.8.2]# source /etc/bashrc

Step 3:核实GIT 版本

完成以上步骤后,使用以下命令检查GIT版本 [xiaolu@lucia git-2.8.2]$ git --version

git version 2.8.2

Step 4:命令补全

Linux的shell环境通过bash-completion软件包提供命令补齐功能,在录入命令参数时按一次或两次TAB键可实现参数的自动补齐或提示 [xiaolu@lucia git-2.8.2]$ sudo cp contrib/completion/git-completion.bash /etc/bash_completion.d/

#将Git源码包中的命令补全脚本肤质到bash-completion对应的目录中

[xiaolu@lucia git-2.8.2]$ . /etc/bash_completion.d/git-completion.bash

#重新加载自动补齐脚本,使之在当前的shell中生效

为了能够在终端开启时自动加载脚本,需要修改/etc/profile文件和~/.bashrc文件 [root@lucia git-2.8.2]# sudo cat >> ~/.bashrc  <

> if [ -f /etc/bash_completion.d/git-completion.bash ]; then

> . /etc/bash_completion.d/git-completion.bash

> fi

> EOF

[xiaolu@lucia git-2.8.2]$ su root

[root@lucia git-2.8.2]# sudo cat >> /etc/profile <

> if [ -f /etc/bash_completion.d/git-completion.bash ]; then

> . /etc/bash_completion.d/git-completion.bash

> fi

> EOF

附1:中文支持

相关说明:

‍ GIT可以在提交说明中使用中文,但是需要对Git进行配置但对于用中文来命名文件、目录和引用,前提是使用UTF-8 字符集的环境下‍

UTF8字符集:

1、在提交时,可以在提交说明中输入中文

2、显示提交历史,能够正常显示提交说明中的中文字符

3、可以添加名称为中文的文件,并可以在同样使用UTF-8字符集的Linux环境中克隆和检出

4、可以创建带有中文字符的里程碑名称

1e251e815be29a34ae39f5c22da3b249.png BUT!!!

❀   在默认设置下,中文文件名在工作区状态输出、查看历史更改概要,以及在补丁文件中,文件名中的中文不能正确的显示,而是显示为八进制的字符编码,如下

[xiaolu@lucia rs-project]$ git status -s

?? "\346\265\213\350\257\225.txt"

[xiaolu@lucia rs-project]$ printf "\346\265\213\350\257\225.txt\n"

测试.txt

❀  解决方法:通过将Git配置变量 core.quotepath 设置为 false

[xiaolu@lucia rs-project]$ git config --global core.quotepath false[xiaolu@lucia rs-project]$

[xiaolu@lucia rs-project]$ git status -s

?? 测试.txt

附2:相关问题

make prefix=/usr/local/git all 报错

目前我碰到的报错有两种:

时间没有校准(看见 in the future 就是时间没有校准,校准后重新make) ake[1]: Warning: File `Makefile' has modification time 2.5e+06 s in the future

/usr/bin/perl Makefile.PL PREFIX='/usr/local' INSTALL_BASE='' --localedir='/usr/local/share/locale'

Writing perl.mak for Git

make[1]: warning:  Clock skew detected.  Your build may be incomplete.

GEN git-add--interactive

make[1]: Warning: File `Makefile' has modification time 2.5e+06 s in the future

Writing perl.mak for Git

make[2]: Warning: File `Makefile.PL' has modification time 2.5e+06 s in the future

Writing perl.mak for Git

make[2]: *** [perl.mak] Error 1

make[1]: *** [instlibdir] Error 2

make: *** [git-add--interactive] Error 2

2. 第二种报依赖包错误,导致make失败

本文OS是纯净版,实际上真正OS环境下许多依赖包已经安装,且通过yum仓库安装的版本都较老,换yum源后将提示的相关依赖包卸载(rpm -e),然后重新yum安装一下

#-------------------------------------------------------------------------------------------------------------------#

f66dcdfa4e7dba58ad1d0b5076d4bebe.png

Lucia   2016/05

#-------------------------------------------------------------------------------------------------------------------#

附3:记住GIT账户和密码(2016/09新增)

# 以这种格式 https://{username}:{password}@git.oschina.net写入隐藏文件.git-credentials

[xiaolu@lucia ~]$ echo https://{luciaxxx@163.com}:{xxxxxx}@git.oschina.net >> .git-credentials

[xiaolu@lucia ~]$ cat .git-credentials

https://{luciaxxx@163.com}:{xxxxxx}@git.oschina.net

# 运行git配置命令

[xiaolu@lucia ~]$ git config --global credential.helper store

[xiaolu@lucia ~]$ cat .gitconfig

[credential]

helper = store

# 第一次拉取仓库时仍需要输入用户名及密码进行验证

[xiaolu@lucia ~]$ git clone https://git.oschina.net/lucia-moore/Auto-Install.git

Cloning into 'Auto-Install'...

Username for 'https://git.oschina.net': luciaxxx@163.com

Password for 'https://luciaxxx@163.com@git.oschina.net':

remote: Counting objects: 3, done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

Checking connectivity... done.

[xiaolu@lucia ~]$ ls

Auto-Install

#此时查看文件.git-credentials会多出一项,证明配置成功了

[xiaolu@lucia ~]$ cat .git-credentials

https://luciaxxx%40163.com:xxxxxx@git.oschina.net

https://{luciaxxx@163.com}:{xxxxxx}@git.oschina.net

#此时 git pull 就不需要输入用户名和密码直接pull

[xiaolu@lucia ~]$ cd Auto-Install/

[xiaolu@lucia Auto-Install]$ git pull https://git.oschina.net/lucia-moore/Auto-Install.git

From https://git.oschina.net/lucia-moore/Auto-Install

* branch HEAD -> FETCH_HEAD

Already up-to-date.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值