debian 安装 git_如何在Debian 10上安装Git

debian 安装 git

介绍 (Introduction)

Software version control systems like Git enable you to keep track of your software at the source level. With versioning tools, you can track changes, revert to previous stages, and branch to create alternate versions of files and directories.

像Git这样的软件版本控制系统使您能够在源代码级别跟踪软件。 使用版本控制工具,您可以跟踪更改,还原到上一阶段以及分支以创建文件和目录的备用版本。

As one of the most popular version control systems currently available, Git is a common choice among open-source and other collaborative software projects. Many projects’ files are maintained in a Git repository, and sites like GitHub, GitLab, and Bitbucket help to facilitate software development project sharing and collaboration.

作为当前可用的最受欢迎的版本控制系统之一,Git是开源和其他协作软件项目中的常见选择。 许多项目的文件都保存在Git存储库中,而GitHub,GitLab和Bitbucket等站点则有助于促进软件开发项目的共享和协作。

In this tutorial, we’ll install and configure Git on a Debian 10 server. We will cover how to install the software in two different ways, each of which have their own benefits depending on your specific needs.

在本教程中,我们将在Debian 10服务器上安装和配置Git。 我们将介绍如何以两种不同的方式安装软件,每种方式都有自己的优势,具体取决于您的特定需求。

先决条件 (Prerequisites)

In order to complete this tutorial, you should have a non-root user with sudo privileges on an Debian 10 server. To learn how to achieve this setup, follow our Debian 10 initial server setup guide.

为了完成本教程,您应该在Debian 10服务器上拥有一个具有sudo特权的非root用户。 要了解如何实现此设置,请遵循Debian 10初始服务器设置指南

With your server and user set up, you are ready to begin. Jump to Installing Git with Default Packages (via the apt package manager) or Installing Git from Source to begin.

设置好服务器和用户后,就可以开始了。 跳转至使用默认软件包安装Git (通过apt软件包管理器)或从源代码安装Git开始。

使用默认软件包安装Git (Installing Git with Default Packages)

Debian’s default repositories provide you with a fast method to install Git. Note that the version you install via these repositories may be older than the newest version currently available. If you need the latest release, consider moving to the next section of this tutorial to learn how to install and compile Git from source.

Debian的默认存储库为您提供了一种安装Git的快速方法。 请注意,通过这些存储库安装的版本可能早于当前可用的最新版本。 如果您需要最新版本,请考虑转到本教程的下一部分 ,以学习如何从源代码安装和编译Git。

First, use the apt package management tools to update your local package index. With the update complete, you can download and install Git:

首先,使用apt软件包管理工具更新您的本地软件包索引。 完成更新后,您可以下载并安装Git:

  • sudo apt update

    sudo apt更新
  • sudo apt install git

    sudo apt安装git

You can confirm that you have installed Git correctly by running the following command:

您可以通过运行以下命令来确认已正确安装了Git:

  • git --version

    git --version

   
   
Output
git version 2.20.1

With Git successfully installed, you can now move on to the Setting Up Git section of this tutorial to complete your setup.

成功安装Git后,您现在可以转到本教程的“ 设置Git”部分以完成设置。

从源代码安装Git (Installing Git from Source)

A more flexible method of installing Git is to compile the software from source. This takes longer and will not be maintained through your package manager, but it will allow you to download the latest release and will give you some control over the options you include if you wish to customize.

安装Git的一种更灵活的方法是从源代码编译软件。 这将花费更长的时间,并且不会通过软件包管理器进行维护,但是它将允许您下载最新版本,并且如果您希望自定义的话,还可以控制您包括的选项。

Before you begin, you need to install the software that Git depends on. This is all available in the default repositories, so we can update our local package index and then install the packages.

在开始之前,您需要安装Git依赖的软件。 这些在默认存储库中都可用,因此我们可以更新本地软件包索引,然后安装软件包。

  • sudo apt update

    sudo apt更新
  • sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

    sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext解压缩

After you have installed the necessary dependencies, you can go ahead and get the version of Git you would like to install by visiting the Git project’s mirror on GitHub, available via the following URL:

在安装了必要的依赖项之后,您可以继续访问GitHub上Git项目镜像 ,以获取要安装的Git版本,该镜像可通过以下URL获得:

https://github.com/git/git

From here, be sure that you are on the master branch. Click on the Tags link and select your desired Git version. Unless you have a reason for downloading a release candidate version (marked as rc), try to avoid these as they may be unstable.

从这里,确保您在master分支上。 单击标签链接,然后选择所需的Git版本。 除非您有理由下载候选发布版本(标记为rc ),否则请尽量避免使用这些版本,因为它们可能不稳定。

Next, on the right side of the page, click on the Clone or download button, then right-click on Download ZIP and copy the link address that ends in .zip.

接下来,在页面右侧,单击“ 克隆”或“下载”按钮,然后右键单击“ 下载ZIP”并复制以.zip结尾的链接地址。

Back on your Debian 10 server, move into the tmp directory to download temporary files.

返回Debian 10服务器,移至tmp目录以下载临时文件。

  • cd /tmp

    cd / tmp

From there, you can use the wget command to install the copied zip file link. We’ll specify a new name for the file: git.zip.

从那里,您可以使用wget命令安装复制的zip文件链接。 我们将为文件指定一个新名称: git.zip

  • wget https://github.com/git/git/archive/v2.23.0.zip -O git.zip

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

Unzip the file that you downloaded and move into the resulting directory by typing:

解压缩下载的文件,并通过键入以下内容进入结果目录:

  • unzip git.zip

    解压缩git.zip
  • cd git-*

    cd git- *

Now, you can make the package and install it by typing these two commands:

现在,您可以通过键入以下两个命令来制作软件包并进行安装:

  • make prefix=/usr/local all

    使prefix = / usr / local全部
  • sudo make prefix=/usr/local install

    sudo make prefix = / usr /本地安装

To ensure that the install was successful, you can type git --version and you should receive relevant output that specifies the current installed version of Git.

为了确保安装成功,您可以键入git --version并且您应该收到指定Git当前安装版本的相关输出。

Now that you have Git installed, if you want to upgrade to a later version, you can clone the repository, and then build and install. To find the URL to use for the clone operation, navigate to the branch or tag that you want on the project’s GitHub page and then copy the clone URL on the right side:

现在已经安装了Git,如果要升级到更高版本,则可以克隆存储库,然后进行构建和安装。 要查找用于克隆操作的URL,请在项目的GitHub页面上导航至所需的分支或标记,然后在右侧复制克隆URL:

At the time of writing, the relevant URL is:

在撰写本文时,相关的URL为:

https://github.com/git/git.git

Change to your home directory, and use git clone on the URL you just copied:

转到您的主目录,并在刚复制的URL上使用git clone

  • cd ~

    光盘〜
  • git clone https://github.com/git/git.git

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

This will create a new directory within your current directory where you can rebuild the package and reinstall the newer version, just like you did above. This will overwrite your older version with the new version:

这将在当前目录中创建一个新目录,您可以在其中重建软件包并重新安装较新的版本,就像您在上面所做的那样。 这将用新版本覆盖旧版本:

  • cd git

    光盘git
  • make prefix=/usr/local all

    使prefix = / usr / local全部
  • sudo make prefix=/usr/local install

    sudo make prefix = / usr /本地安装

With this complete, you can be sure that your version of Git is up to date.

完成此操作后,您可以确保您的Git版本是最新的。

设置Git (Setting Up Git)

Now that you have Git installed, you should configure it so that the generated commit messages will contain your correct information.

既然已经安装了Git,则应该对其进行配置,以便生成的提交消息将包含正确的信息。

This can be achieved by using the git config command. Specifically, we need to provide our name and email address because Git embeds this information into each commit we do. We can go ahead and add this information by typing:

这可以通过使用git config命令来实现。 具体来说,我们需要提供我们的姓名和电子邮件地址,因为Git会将这些信息嵌入到我们所做的每次提交中。 我们可以继续输入以下内容来添加此信息:

  • git config --global user.name "Sammy"

    git config --global user.name“ 萨米 ”

  • git config --global user.email "sammy@domain.com"

    git config --global user.email“ sammy@domain.com ”

We can see all of the configuration items that have been set by typing:

我们可以通过键入以下命令查看已设置的所有配置项:

  • git config --list

    git config --list

   
   
Output
user.name=Sammy user.email=sammy@domain.com ...

The information you enter is stored in your Git configuration file, which you can optionally edit by hand with a text editor like this:

输入的信息存储在Git配置文件中,您可以选择使用文本编辑器手动编辑该文件,如下所示:

  • nano ~/.gitconfig

    纳米〜/ .gitconfig
~/.gitconfig contents
〜/ .gitconfig内容
[user]
  name = Sammy
  email = sammy@domain.com

There are many other options that you can set, but these are the two essential ones needed. If you skip this step, you’ll likely see warnings when you commit to Git. This makes more work for you because you will then have to revise the commits you have done with the corrected information.

您可以设置许多其他选项,但这是需要的两个基本选项。 如果跳过此步骤,则在提交到Git时可能会看到警告。 这将为您带来更多的工作,因为您将不得不使用更正的信息来修改您所做的提交。

结论 (Conclusion)

You should now have Git installed and ready to use on your system.

现在,您应该已经安装了Git,可以在系统上使用它了。

To learn more about how to use Git, check out these articles and series:

要了解有关如何使用Git的更多信息,请查看以下文章和系列:

Additionally, you can learn more by reviewing our series on An Introduction to Open Source for more information about using Git as part of open-source projects.

此外,您可以阅读我们的“ 开源简介”系列了解更多有关使用Git作为开源项目一部分的信息。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-git-on-debian-10

debian 安装 git

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值