Git 安装配置

12 篇文章 0 订阅
本文详细介绍了在Linux和Windows平台上安装Git的过程,包括依赖库的安装、Git的配置,如设置用户信息和编辑器,以及如何查看和修改配置。此外,还提到了Git的版本信息和如何卸载旧版本。对于Windows用户,提供了msysGit的安装步骤和GitBash的使用。文章还简单提及了Git的基本操作和工作流程。
摘要由CSDN通过智能技术生成

Git详述:https://mp.csdn.net/mp_blog/creation/editor/119935707

Git 工作流程:https://mp.csdn.net/mp_blog/creation/editor/119945322

Git 工作区、暂存区和版本库:https://mp.csdn.net/mp_blog/creation/editor/119945402

Git 创建仓库:https://mp.csdn.net/mp_blog/creation/editor/119948151

Git 基本操作:https://mp.csdn.net/mp_blog/creation/editor/119949390

Git 分支管理:https://mp.csdn.net/mp_blog/creation/editor/119951024

Git 查看提交历史:https://mp.csdn.net/mp_blog/creation/editor/119951662

Git 标签:https://mp.csdn.net/mp_blog/creation/editor/119951922

Git 远程仓库(Github):https://mp.csdn.net/mp_blog/creation/editor/119952396

Git Gitee:https://mp.csdn.net/mp_blog/creation/editor/119953973

Git 服务器搭建:https://mp.csdn.net/mp_blog/creation/editor/119954105

一 Linux 平台上安装

Git 的工作需要调用 curl,zlib,openssl,expat,libiconv 等库的代码,所以需要先安装这些依赖工具。

在有 yum 的系统上(比如 Fedora)或者有 apt-get 的系统上(比如 Debian 体系),可以用下面的命令安装:

各 Linux 系统可以使用其安装包管理工具(apt-get、yum 等)进行安装

Debian/Ubuntu(安装命令)

$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
  libz-dev libssl-dev

$ apt-get install git

$ git --version
git version 1.8.1.2

Centos/RedHat(安装命令)

$ yum install curl-devel expat-devel gettext-devel \
  openssl-devel zlib-devel

$ yum -y install git-core

$ git --version
git version 1.7.1

 二 Windows 平台上安装

在 Windows 平台上安装 Git 同样轻松,有个叫做 msysGit 的项目提供了安装包,可以到 GitHub 的页面上下载 exe 安装文件并运行:

安装包下载地址:https://gitforwindows.org/

官网慢,可以用国内的镜像:https://npm.taobao.org/mirrors/git-for-windows/

完成安装之后,就可以使用命令行的 git 工具(已经自带了 ssh 客户端)了,另外还有一个图形界面的 Git 项目管理工具。

在开始菜单里找到"Git"->"Git Bash",会弹出 Git 命令窗口,你可以在该窗口进行 Git 操作。

三 Git 配置

用户信息

配置个人的用户名称和电子邮件地址:

$ git config --global user.name "runoob"
$ git config --global user.email test@runoob.com

如果用了 --global 选项,那么更改的配置文件就是位于你用户主目录下的那个,以后你所有的项目都会默认使用这里配置的用户信息。

如果要在某个特定的项目中使用其他名字或者电邮,只要去掉 --global 选项重新配置即可,新的设定保存在当前项目的 .git/config 文件里。

文本编辑器

Git默认使用的文本编辑器, 一般可能会是 Vi 或者 Vim

差异分析工具

还有一个比较常用的是,在解决合并冲突时使用哪种差异分析工具。比如要改用 vimdiff 的话:

$ git config --global merge.tool vimdiff

查看配置信息

$ git config --list

也可以直接查阅某个环境变量的设定,只要把特定的名字跟在后面即可,像这样:

 git config user.name

移除旧版本git

centos自带Git,7.x版本自带git 1.8.3.1(应该是,也可能不是), 安装新版本之前需要使用yum remove git卸载(安装后卸载也可以)。

git --version    ## 查看自带的版本
yum remove git   ## 移除原来的版本

3 安装所需软件包

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel 
yum install gcc-c++ perl-ExtUtils-MakeMaker

下载&安装

cd /usr/src
 wget https://www.kernel.org/pub/software/scm/git/git-2.7.3.tar.gz

5 解压

tar xf git-2.7.3.tar.gz

6 配置编译安装

[root@Git ~]# cd git-2.7.3
[root@Git ~]# make configure
[root@Git ~]# ./configure --prefix=/usr/git ##配置目录
[root@Git ~]# make profix=/usr/git
[root@Git ~]# make install

7 加入环境变量

echo 'export PATH=$PATH:/usr/git/bin' >> /etc/profile
 source /etc/profile

8 检查版本

git --version 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值