金钱(警告)
状态: 被剥夺
本文涵盖了不再受支持的 CentOS 版本. 如果您目前正在运行运行 CentOS 6 的服务器,我们强烈建议升级或迁移到受支持的 CentOS 版本。
** 原因** : CentOS 6于2020年11月30日到期(EOL)并且不再收到安全补丁或更新。
See Instead : 本指南可能仍然有用作为参考,但可能不会在其他 CentOS 版本上工作. 如果可用,我们强烈建议使用为您正在使用的 CentOS 版本撰写的指南。
下面的DigitalOcean教程可能立即感兴趣,因为它概述了在CentOS 7服务器上安装Git:
美元
介绍
Git是一个开源的分布式版本控制系统,由Linus Torvalds,Linux的创造者开发,它具有微妙的分支和合并,能够管理单个项目的多个远程存储库,以及真正的分布式开发。
虽然Git在管理数百或数千名贡献者的大型,复杂的项目方面非常出色,但它也可以在一个人的或小团队的小型项目中非常出色,这种灵活性使其成为实现任何规模的软件项目的版本和源控制的绝佳选择。
在本文中,我们将介绍如何在 CentOS 6.4 服务器上安装 git,使用 CentOS 包管理器 `yum。
如何使用Yum安装Git
与大多数Linux发行版一样,git可以从CentOS的默认存储库中获取,我们可以通过:
1sudo yum install git
您将不得不输入y
来确认安装,然后 git 将被安装并准备好使用。
如何在CentOS上安装Git from Source
如果你想要Git的最新版本,你最好从源头下载最新的版本并从那里编译。
在本文中 CentOS 存储库中的版本为 1.7.1,而 Git 的最新版本为 1.8.4,这是一个显著的区别。
首先,我们需要使用以下命令下载 CentOS 的编译工具:
1sudo yum groupinstall "Development Tools"
这将安装必要的工具和编译器来将源代码转换为二进制执行。
一旦完成,我们需要安装一些Git需要构建或运行的额外依赖:
1sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel
一旦安装,您可以从托管在 github.com的代码中获取最新版本的 git:
1cd ~
2wget -O git.zip https://github.com/git/git/archive/master.zip
解开档案并更改到项目目录:
1unzip git.zip
2cd git-master
我们可以计算包,构建可执行和文档,然后用以下命令组安装它:
1make configure
2./configure --prefix=/usr/local
3make all doc
4sudo make install install-doc install-html
要稍后更新 git,您可以使用 git! 将 github 上的 git 存储库克隆成一个新的目录,然后像以前那样构建和安装它:
1git clone git://github.com/git/git
如何设置Git
当您使用 git 进行更改时,它将您的姓名和电子邮件地址嵌入到 commit 消息中,以便轻松跟踪更改。
如果我们自己不配置这些信息,git 可能会尝试通过使用您的 Linux 用户名和主机名来猜测这些值(可能不正确)。
使用这些命令给出您想要使用这些参数的 git 值:
git config --global user.name "Your Name Here" git config --global user.email "[email protected]"
配置更改将存储在您的主目录中的文件中,您可以使用正常的文本编辑器查看它们:
1nano ~/.gitconfig
1[user]
2 name = Your Name Here
3 email = [email protected]
您也可以通过查询 git 本身查看当前配置设置来查看此信息:
1git config --list
1user.name=Your Name Here
2[email protected]
如前所述,如果您忘记设置这些步骤,git 可能会尝试自动填写这些值:
1[master 0d9d21d] initial project version
2 Committer: root
3Your name and email address were configured automatically based
4on your username and hostname. Please check that they are accurate.
5You can suppress this message by setting them explicitly:
6
7 git config --global user.name "Your Name"
8 git config --global user.email [email protected]
9
10After doing this, you may fix the identity used for this commit with:
11
12 git commit --amend --reset-author
根据您的 git 版本,它可能会完全失败:
git commit
*** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: empty ident name (for) not allowed
正如你所看到的,Git非常擅长告诉你应该做什么。
结论
现在你已经安装了 git 并可以开始学习一些基本的使用方法. 我们有几个教程,可以好好看看:
Git是一个工具,在基本的理解下立即变得有用,随着知识的增长,它继续提供优势。