Installing Git [安装 Git]
- 1. Installing Git
- 1.1. Description
- 1.2. Installing on Linux (在 Linux 上安装)
- 1.3. Installing on macOS (在 macOS 上安装)
- 1.4. Installing on Windows (在 Windows 上安装)
- 1.5. Installing from Source (从源代码安装)
- 2. `sudo apt-get install git`
- 3. `git version`
- References
Pro Git (SECOND EDITION)
https://git-scm.com/book/en/v2
Pro Git (SECOND EDITION)
https://git-scm.com/book/zh/v2
1. Installing Git
1.1. Description
检查系统中是否安装了 git
:
strong@foreverstrong:~$ git
usage: git [--version] [--help] [-C <path>] [-c name=value][--exec-path[=<path>]] [--html-path] [--man-path] [--info-path][-p | --paginate | --no-pager] [--no-replace-objects] [--bare][--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]<command> [<args>]These are common Git commands used in various situations:start a working area (see also: git help tutorial)clone Clone a repository into a new directoryinit Create an empty Git repository or reinitialize an existing onework on the current change (see also: git help everyday)add Add file contents to the indexmv Move or rename a file, a directory, or a symlinkreset Reset current HEAD to the specified staterm Remove files from the working tree and from the indexexamine the history and state (see also: git help revisions)bisect Use binary search to find the commit that introduced a buggrep Print lines matching a patternlog Show commit logsshow Show various types of objectsstatus Show the working tree statusgrow, mark and tweak your common historybranch List, create, or delete branchescheckout Switch branches or restore working tree filescommit Record changes to the repositorydiff Show changes between commits, commit and working tree, etcmerge Join two or more development histories togetherrebase Forward-port local commits to the updated upstream headtag Create, list, delete or verify a tag object signed with GPGcollaborate (see also: git help workflows)fetch Download objects and refs from another repositorypull Fetch from and integrate with another repository or a local branchpush Update remote refs along with associated objects'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
1.2. Installing on Linux (在 Linux 上安装)
If you want to install the basic Git tools on Linux via a binary installer, you can generally do so through the package management tool that comes with your distribution. If you’re on Fedora (or any closely-related RPM-based distribution, such as RHEL or CentOS), you can use dnf
:
$ sudo dnf install git-all
If you’re on a Debian-based distribution, such as Ubuntu, try apt
:
$ sudo apt install git-all
For more options, there are instructions for installing on several different Unix distributions on the Git website, at https://git-scm.com/download/linux.
1.3. Installing on macOS (在 macOS 上安装)
There are several ways to install Git on macOS. The easiest is probably to install the Xcode Command Line Tools. On Mavericks (10.9) or above you can do this simply by trying to run git
from the Terminal the very first time.
在 Mac 上安装 Git 有多种方式。最简单的方法是安装 Xcode Command Line Tools。
$ git --version
If you don’t have it installed already, it will prompt you to install it.
如果没有安装过命令行开发者工具,将会提示你安装。
If you want a more up to date version, you can also install it via a binary installer. A macOS Git installer is maintained and available for download at the Git website, at https://git-scm.com/download/mac.
如果你想安装更新的版本,可以使用二进制安装程序。 官方维护的 macOS Git 安装程序可以在 Git 官方网站下载,网址为 https://git-scm.com/download/mac。
1.4. Installing on Windows (在 Windows 上安装)
The most official build is available for download on the Git website. Just go to https://git-scm.com/download/win and the download will start automatically. Note that this is a project called Git for Windows, which is separate from Git itself; for more information on it, go to https://gitforwindows.org.
官方版本可以在 Git 官方网站下载。
1.5. Installing from Source (从源代码安装)
If you do want to install Git from source, you need to have the following libraries that Git depends on: autotools, curl, zlib, openssl, expat, and libiconv. For example, if you’re on a system that has dnf
(such as Fedora) or apt-get
(such as a Debian-based system), you can use one of these commands to install the minimal dependencies for compiling and installing the Git binaries:
$ sudo dnf install dh-autoreconf curl-devel expat-devel gettext-devel \openssl-devel perl-devel zlib-devel
$ sudo apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev \gettext libz-dev libssl-dev
In order to be able to add the documentation in various formats (doc, html, info), these additional dependencies are required:
$ sudo dnf install asciidoc xmlto docbook2X
$ sudo apt-get install asciidoc xmlto docbook2x
If you’re using a Debian-based distribution (Debian/Ubuntu/Ubuntu-derivatives), you also need the install-info
package:
$ sudo apt-get install install-info
If you’re using a RPM-based distribution (Fedora/RHEL/RHEL-derivatives), you also need the getopt
package (which is already installed on a Debian-based distro):
$ sudo dnf install getopt
Additionally, if you’re using Fedora/RHEL/RHEL-derivatives, you need to do this:
$ sudo ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
due to binary name differences.
When you have all the necessary dependencies, you can go ahead and grab the latest tagged release tarball from several places. You can get it via the kernel.org site, at https://www.kernel.org/pub/software/scm/git, or the mirror on the GitHub website, at https://github.com/git/git/tags. It’s generally a little clearer what the latest version is on the GitHub page, but the kernel.org page also has release signatures if you want to verify your download.
通常在 GitHub 上的是最新版本,但 kernel.org 上包含有文件下载签名,如果你想验证下载正确性的话会用到。
Then, compile and install:
$ tar -zxf git-2.8.0.tar.gz
$ cd git-2.8.0
$ make configure
$ ./configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info
After this is done, you can also get Git via Git itself for updates:
$ git clone https://git.kernel.org/pub/scm/git/git.git
2. sudo apt-get install git
strong@ubuntu:~$ git clone https://github.com/pjreddie/darknet.git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
strong@ubuntu:~$ sudo apt-get install git
3. git version
strong@foreverstrong:~$ git --version
git version 2.7.4
References
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/