Git安装与配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git安装与配置相关的知识,希望对你有一定的参考价值。
(一)Git概述
Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。[2] Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。
Git 与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持。
----------百度百科
Git 与 SVN 区别点:
1、GIT是分布式的,SVN是集中式的:这是GIT和其它非分布式的版本控制系统,例如SVN,CVS等,最核心的区别。
2、GIT把内容按元数据方式存储,而SVN是按文件:所有的资源控制系统都是把文件的元信息隐藏在一个类似.svn,.cvs等的文件夹里。
3、GIT分支和SVN的分支不同:分支在SVN中一点不特别,就是版本库中的另外的一个目录。
4、GIT没有一个全局的版本号,而SVN有:目前为止这是跟SVN相比GIT缺少的最大的一个特征。
5、GIT的内容完整性要优于SVN:GIT的内容存储使用的是SHA-1哈希算法。这能确保代码内容的完整性,确保在遇到磁盘故障和网络问题时降低对版本库的破坏。
(二)Git安装
Git 的工作需要调用 curl,zlib,openssl,expat,libiconv 等库的代码,所以需要先安装这些依赖工具。在有 yum 的系统上(比如 Fedora)或者有 apt-get 的系统上(比如 Debian 体系),可以用下面的命令安装:
(1)Linux平台上安装(CentOS/Redhat)git服务端
1.#######安装git所对应的编译包 [[email protected] ~]# yum install curl-devel expat-devel gettext-devel > openssl-devel zlib-devel Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn * extras: ftp.sjtu.edu.cn * updates: mirror.bit.edu.cn Package expat-devel-2.1.0-10.el7_3.x86_64 already installed and latest version Package 1:openssl-devel-1.0.1e-60.el7_3.1.x86_64 already installed and latest version Package zlib-devel-1.2.7-17.el7.x86_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package gettext-devel.x86_64 0:0.18.2.1-4.el7 will be installed --> Processing Dependency: gettext-common-devel = 0.18.2.1-4.el7 for package: gettext-devel-0.18.2.1-4.el7.x86_64 ---> Package libcurl-devel.x86_64 0:7.29.0-35.el7.centos will be installed base/7/x86_64/filelists_db | 6.6 MB 00:00 --> Processing Dependency: libcurl = 7.29.0-35.el7.centos for package: libcurl-devel-7.29.0-35.el7.centos.x86_64 --> Running transaction check ---> Package gettext-common-devel.noarch 0:0.18.2.1-4.el7 will be installed ---> Package libcurl.x86_64 0:7.29.0-25.el7.centos will be updated --> Processing Dependency: libcurl = 7.29.0-25.el7.centos for package: curl-7.29.0-25.el7.centos.x86_64 ---> Package libcurl.x86_64 0:7.29.0-35.el7.centos will be an update --> Running transaction check ---> Package curl.x86_64 0:7.29.0-25.el7.centos will be updated ---> Package curl.x86_64 0:7.29.0-35.el7.centos will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: gettext-devel x86_64 0.18.2.1-4.el7 base 315 k libcurl-devel x86_64 7.29.0-35.el7.centos base 299 k Installing for dependencies: gettext-common-devel noarch 0.18.2.1-4.el7 base 368 k Updating for dependencies: curl x86_64 7.29.0-35.el7.centos base 265 k libcurl x86_64 7.29.0-35.el7.centos base 218 k Transaction Summary ================================================================================ Install 2 Packages (+1 Dependent package) Upgrade ( 2 Dependent packages) Total download size: 1.4 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/5): curl-7.29.0-35.el7.centos.x86_64.rpm | 265 kB 00:00 (2/5): gettext-common-devel-0.18.2.1-4.el7.noarch.rpm | 368 kB 00:00 (3/5): gettext-devel-0.18.2.1-4.el7.x86_64.rpm | 315 kB 00:00 (4/5): libcurl-7.29.0-35.el7.centos.x86_64.rpm | 218 kB 00:00 (5/5): libcurl-devel-7.29.0-35.el7.centos.x86_64.rpm | 299 kB 00:00 -------------------------------------------------------------------------------- Total 6.0 MB/s | 1.4 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : libcurl-7.29.0-35.el7.centos.x86_64 1/7 Installing : gettext-common-devel-0.18.2.1-4.el7.noarch 2/7 Installing : gettext-devel-0.18.2.1-4.el7.x86_64 3/7 Updating : curl-7.29.0-35.el7.centos.x86_64 4/7 Installing : libcurl-devel-7.29.0-35.el7.centos.x86_64 5/7 Cleanup : curl-7.29.0-25.el7.centos.x86_64 6/7 Cleanup : libcurl-7.29.0-25.el7.centos.x86_64 7/7 Verifying : curl-7.29.0-35.el7.centos.x86_64 1/7 Verifying : gettext-common-devel-0.18.2.1-4.el7.noarch 2/7 Verifying : libcurl-7.29.0-35.el7.centos.x86_64 3/7 Verifying : gettext-devel-0.18.2.1-4.el7.x86_64 4/7 Verifying : libcurl-devel-7.29.0-35.el7.centos.x86_64 5/7 Verifying : libcurl-7.29.0-25.el7.centos.x86_64 6/7 Verifying : curl-7.29.0-25.el7.centos.x86_64 7/7 Installed: gettext-devel.x86_64 0:0.18.2.1-4.el7 libcurl-devel.x86_64 0:7.29.0-35.el7.centos Dependency Installed: gettext-common-devel.noarch 0:0.18.2.1-4.el7 Dependency Updated: curl.x86_64 0:7.29.0-35.el7.centos libcurl.x86_64 0:7.29.0-35.el7.centos Complete!
2.##########通过yum进行安装 [[email protected] ~]# yum -y install git-core 已加载插件:fastestmirror 设置安装进程 Loading mirror speeds from cached hostfile * epel: mirrors.tuna.tsinghua.edu.cn 解决依赖关系 --> 执行事务检查 ---> Package git.x86_64 0:1.7.1-4.el6_7.1 will be 升级 --> 处理依赖关系 git = 1.7.1-4.el6_7.1,它被软件包 perl-Git-1.7.1-4.el6_7.1.noarch 需要 ---> Package git.x86_64 0:1.7.1-9.el6_9 will be an update --> 执行事务检查 ---> Package perl-Git.noarch 0:1.7.1-4.el6_7.1 will be 升级 ---> Package perl-Git.noarch 0:1.7.1-9.el6_9 will be an update --> 完成依赖关系计算 依赖关系解决 ================================================================================ 软件包 架构 版本 仓库 大小 ================================================================================ 正在升级: git x86_64 1.7.1-9.el6_9 updates 4.6 M 为依赖而更新: perl-Git noarch 1.7.1-9.el6_9 updates 29 k 事务概要 ================================================================================ Upgrade 2 Package(s) 总下载量:4.6 M 下载软件包: (1/2): git-1.7.1-9.el6_9.x86_64.rpm | 4.6 MB 00:00 (2/2): perl-Git-1.7.1-9.el6_9.noarch.rpm | 29 kB 00:00 -------------------------------------------------------------------------------- 总计 889 kB/s | 4.6 MB 00:05 运行 rpm_check_debug 执行事务测试 事务测试成功 执行事务 正在升级 : perl-Git-1.7.1-9.el6_9.noarch 1/4 正在升级 : git-1.7.1-9.el6_9.x86_64 2/4 清理 : perl-Git-1.7.1-4.el6_7.1.noarch 3/4 清理 : git-1.7.1-4.el6_7.1.x86_64 4/4 Verifying : git-1.7.1-9.el6_9.x86_64 1/4 Verifying : perl-Git-1.7.1-9.el6_9.noarch 2/4 Verifying : perl-Git-1.7.1-4.el6_7.1.noarch 3/4 Verifying : git-1.7.1-4.el6_7.1.x86_64 4/4 更新完毕: git.x86_64 0:1.7.1-9.el6_9 作为依赖被升级: perl-Git.noarch 0:1.7.1-9.el6_9 完毕!
3.########查看版本信息 [[email protected] ~]# git --version git version 1.8.3.1
4.创建git用户,用来运行git服务 [[email protected] ~]# useradd git -s /sbin/nologin -M
5.创建客户端登录证书。一路回车即可,将生成的id_rsa.pub,复制给管理员,帮你在服务器上增加一下,下次你用git时就不需要输入用户名和密码了。 [[email protected] ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: f3:bb:45:5c:83:21:70:06:f0:ab:87:2c:9e:11:2e:68 [email protected] The key‘s randomart image is: +--[ RSA 2048]----+ | ..oo+ . | | . o . o | | . . o | | . . . . | | . S o | | . . o o o . | |.E. + + . . . | |. o + . o | | o o. | +-----------------+ [[email protected] ~]# cat /root/.ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvPX0EADLEd7PkDB2KvGssNFswZ4ovLZkuNDAH+425EtrpKn6cPjceb+yajqAd6bpXtzpp1ZbAusizlN4JulXdOPO8cj5yEoCqjkWzD0f0do3eybC+NE/jBFqgViNi6DQtAEmkzhqsSw/YKOStO09r/D2egv4J8DDF09ZQN0dibU7prRHRLkppTxhypw8xm9B6znPWnl0e1Yn64A/lYy/EVp2H4SpMknZhfcD0qpUZyWyO1LecP1rbiBOeak5UVYFzH7iJ++7RULi2VVnq93FpyLvVNQTLwm0s4RiiKZdRKflk6DP9sHPjZROD1+iXepHnyTAEungWRnmyjuYXVySgw== [email protected] ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAytLVeZyNACFK+/PjBXUvMHNJ7HiS/9bsTSIKQEhLRtMxOinexadnp/AlKQaUYEblIEi7FkXcCDTR18EefFu4wCptzMUs8W8kxw6u1TN0jx2Y+7Eo7MbH6MRuA9fehwgtiPdPbsMiu400LIq+zlZOvJY3E/QX3pvvAbbXhu61fraffFWSkGEyELOApacC0aJfnEBSYfcCa7flWGjvKhUCC1YJP/qn40X+l6sGJ/+ZTItETZ+r7IayQwpPpFMUt5hmIYgCE6V8eG/wN2VlBq24xnBk+wDVPwd5p++KwQT9xndcLQbecmBaqtdLF8OgMN0DngQatymP0jHZQHsxM3VmUw== [email protected] ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvPX0EADLEd7PkDB2KvGssNFswZ4ovLZkuNDAH+425EtrpKn6cPjceb+yajqAd6bpXtzpp1ZbAusizlN4JulXdOPO8cj5yEoCqjkWzD0f0do3eybC+NE/jBFqgViNi6DQtAEmkzhqsSw/YKOStO09r/D2egv4J8DDF09ZQN0dibU7prRHRLkppTxhypw8xm9B6znPWnl0e1Yn64A/lYy/EVp2H4SpMknZhfcD0qpUZyWyO1LecP1rbiBOeak5UVYFzH7iJ++7RULi2VVnq93FpyLvVNQTLwm0s4RiiKZdRKflk6DP9sHPjZROD1+iXepHnyTAEungWRnmyjuYXVySgw== [email protected]
(2)安装windos平台的git客户端
1,下载客户端。下载地址如下:https://git-scm.com/downloads
2,windows安装比较简单基本上都是下一步下一步,见下图
(3)安装Linux平台的git客户端(https://www.kernel.org/pub/software/scm/git/ 或者https://github.com/git/git/releases )
[[email protected] ~]# yum install git -y Loaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.7 kB 00:00 extras | 3.4 kB 00:00 extras/primary_db | 29 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 4.7 MB 00:00 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package git.x86_64 0:1.7.1-9.el6_9 will be installed --> Processing Dependency: perl-Git = 1.7.1-9.el6_9 for package: git-1.7.1-9.el6_9.x86_64 --> Processing Dependency: rsync for package: git-1.7.1-9.el6_9.x86_64 --> Processing Dependency: perl(Git) for package: git-1.7.1-9.el6_9.x86_64 --> Processing Dependency: perl(Error) for package: git-1.7.1-9.el6_9.x86_64 --> Running transaction check ---> Package perl-Error.noarch 1:0.17015-4.el6 will be installed ---> Package perl-Git.noarch 0:1.7.1-9.el6_9 will be installed ---> Package rsync.x86_64 0:3.0.6-12.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: git x86_64 1.7.1-9.el6_9 updates 4.6 M Installing for dependencies: perl-Error noarch 1:0.17015-4.el6 base 29 k perl-Git noarch 1.7.1-9.el6_9 updates 29 k rsync x86_64 3.0.6-12.el6 base 335 k Transaction Summary ================================================================================ Install 4 Package(s) Total download size: 5.0 M Installed size: 15 M Downloading Packages: (1/4): git-1.7.1-9.el6_9.x86_64.rpm | 4.6 MB 00:00 (2/4): perl-Error-0.17015-4.el6.noarch.rpm | 29 kB 00:00 (3/4): perl-Git-1.7.1-9.el6_9.noarch.rpm | 29 kB 00:00 (4/4): rsync-3.0.6-12.el6.x86_64.rpm | 335 kB 00:00 -------------------------------------------------------------------------------- Total 30 MB/s | 5.0 MB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : 1:perl-Error-0.17015-4.el6.noarch 1/4 Installing : rsync-3.0.6-12.el6.x86_64 2/4 Installing : perl-Git-1.7.1-9.el6_9.noarch 3/4 Installing : git-1.7.1-9.el6_9.x86_64 4/4 Verifying : rsync-3.0.6-12.el6.x86_64 1/4 Verifying : git-1.7.1-9.el6_9.x86_64 2/4 Verifying : perl-Git-1.7.1-9.el6_9.noarch 3/4 Verifying : 1:perl-Error-0.17015-4.el6.noarch 4/4 Installed: git.x86_64 0:1.7.1-9.el6_9 Dependency Installed: perl-Error.noarch 1:0.17015-4.el6 perl-Git.noarch 0:1.7.1-9.el6_9 rsync.x86_64 0:3.0.6-12.el6 Complete! [[email protected] ~]# git --version git version 1.7.1 [[email protected] ~]#
本文出自 “清风明月” 博客,请务必保留此出处http://liqingbiao.blog.51cto.com/3044896/1970979
以上是关于Git安装与配置的主要内容,如果未能解决你的问题,请参考以下文章