在 CentOS 6.4 VPS 上安装 Git 的方法

白如意i 2024-08-16 11:07:03 阅读 79

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。

简介


Git 是由 Linux 的创始人 Linus Torvalds 开发的开源分布式版本控制系统。它具有轻松的分支和合并功能,能够管理单个项目的多个远程存储库,并支持真正的分布式开发。

虽然 git 在管理具有数百或数千名贡献者的大型复杂项目方面表现出色,但它也可以非常适用于由一个人或一个小团队开发的小型项目。这种灵活性使其成为任何规模软件项目实施版本和源代码控制的绝佳选择。

本文将介绍如何在 CentOS 6.4 服务器上使用 <code>yum 包管理器安装 git,并展示如何从源代码安装 git,以便您可以享受最新的改进。

使用 Yum 安装 Git


与大多数 Linux 发行版一样,git 可以从 CentOS 的默认存储库中获取。我们可以使用以下命令安装包维护者的最新版本:

sudo yum install git

您需要输入 “y” 确认安装。安装完成后,git 将被安装并准备就绪。

在 CentOS 上从源代码安装 Git


如果您想要最新版本的 git,最好从源代码中下载最新版本并进行编译。

本文撰写时,CentOS 存储库中的版本为 1.7.1,而最新版本为 1.8.4,这是一个显著的差异。

首先,我们需要使用以下命令为 CentOS 下载编译工具:

sudo yum groupinstall "Development Tools"

这将安装将源代码转换为二进制可执行文件所需的 make 工具和编译器。

完成后,我们需要安装一些 git 需要的额外依赖项,以便构建或运行:

sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel

安装完成后,您可以从托管在 github.com 上的代码获取最新版本的 git:

cd ~

wget -O git.zip https://github.com/git/git/archive/master.zip

解压存档并切换到项目目录:

unzip git.zip

cd git-master

我们可以配置软件包、构建可执行文件和文档,然后使用以下一组命令安装它:

make configure

./configure --prefix=/usr/local

make all doc

sudo make install install-doc install-html

要在以后更新 git,您实际上可以使用 git!将 git 存储库克隆到新目录,然后像之前一样构建和安装它:

git clone git://github.com/git/git

设置 Git


当您使用 git 提交更改时,它会将您的姓名和电子邮件地址嵌入提交消息中,以便轻松跟踪更改。

如果我们不自行配置这些信息,git 可能会尝试猜测这些值(可能不正确),使用您的 Linux 用户名和主机名。

使用以下命令向 git 提供您希望用于这些参数的值:

git config --global user.name "<span class="highlight">Your Name Here</span>"code>

git config --global user.email "<span class="highlight">your_email@example.com</span>"code>

配置更改将存储在您的主目录中的文件中。您可以使用普通文本编辑器查看它们:

nano ~/.gitconfig

[user]

name = Your Name Here

email = your_email@example.com

您还可以通过查询 git 自身的当前配置设置来查看此信息:

git config --list

user.name=Your Name Here

user.email=your_email@example.com

如前所述,如果您忘记设置这些步骤,git 可能会尝试自动填充这些值:

[master 0d9d21d] initial project version

Committer: root

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:

git config --global user.name "Your Name"

git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author

根据您的 git 版本,它可能会完全失败:

git commit

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"

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 <demo@example.(none)>) not allowed

正如您所看到的,git 非常善于告诉您确切应该做什么。

结论


您现在已经安装了 git,并可以开始学习一些基本用法。我们有一些教程可能会对您有所帮助:

如何有效使用 Git

如何使用 Git 分支

Git 是一种工具,只要有基本的理解就能立即发挥作用,并且随着您的知识增长,它将继续提供优势。



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。