「Git」- 安装(Ubuntu、Debian、CentOS、源码编译)

on Ubuntu 18.04.5 LTS

How to Install the Latest Git Version on Ubuntu
Git/Download for Linux and Unix

# 仓库版本的安装
apt-get install git

# 最新版本的安装,for Ubuntu 
add-apt-repository ppa:git-core/ppa
apt update
apt install git

on CentOS 7.x(安装新版本)

IUS/Setup
Update Git to the latest (help)
How to install latest version of git on CentOS 7.x/6.x

# 安装新版本 Git
yum install -y \
    https://repo.ius.io/ius-release-el7.rpm \
    https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum makecache
yum install git2u-all.noarch # 全家桶(11/20/2019 git version 2.16.5)

# 安装更新的版本
# yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm
# yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm
yum install -y http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
yum makecache
yum install -y git #(11/20/2019 git version 2.22.0)

on Windows

Git – Downloading Package/Download for Windows

安装下载即可

通过源码安装

对于 Git 的编译安装,建议参考 BLFS 文档;

建议安装依赖

cURL-7.50.1 (needed to use Git over http, https, ftp or ftps), OpenSSL-1.0.2h, Python-2.7.12

可选软件包

PCRE-8.39, Subversion-1.9.4 with Perl bindings (for git svn),
Tk-8.6.6 (gitk, a simple Git repository viewer, uses Tk at runtime), Valgrind-3.11.0

下面是用于创建 man pages, html docs 和其他的 other docs 的软件包:
xmlto-0.0.28 and asciidoc-8.6.9 or AsciiDoctor, and also dblatex (for the PDF version of the user manual), docbook2x to create info pages

配置、构建、编译、安装

./configure --prefix=/usr/local --with-gitconfig=/etc/gitconfig

# 安装 Git,执行
make
make install

# 如果想同时安装 Git 文档,执行:
make all doc
make install install-doc

安装的可执行程序

https://git-scm.com/docs

git, is the stupid content tracker.

git-cvsserver, is a CVS server emulator for Git.

gitk, is a graphical Git repository browser (needs Tk-8.6.6).

git-receive-pack, is invoked by git send-pack and updates the repository with the information fed from the remote end.

git-shell, is a login shell for SSH accounts to provide restricted Git access.

git-upload-archive, is invoked by git archive –remote and sends a generated archive to the other end over the git protocol.

git-upload-pack, is invoked by git fetch-pack, it discovers what objects the other side is missing, and sends them after packing.

Setup and Config

git
config
help

Getting and Creating Projects

init,创建Git空仓库、或者重新初始化已经存储在的仓库。
clone

Basic Snapshotting

add
status
diff
commit,将变更记录到存储库中
reset
rm
mv

Branching and Merging

branch
checkout
merge,将两个或者多个开发历史合并到一起。
mergetool
log
stash
tag
worktree

Sharing and Updating Projects

fetch,从另一个仓库下载object和ref。
pull
push
remote
submodule

Inspection and Comparison

show
log
diff
shortlog
describe

Patching

apply
cherry-pick
diff
rebase
revert

Debugging

bisect
blame
grep

Email

am
apply
format-patch
send-email
request-pull

External Systems

svn
fast-import

Administration

clean
gc
fsck
reflog
filter-branch
instaweb
archive
bundle

Server Admin

daemon
update-server-info

Plumbing Commands

cat-file
check-ignore
checkout-index
commit-tree
count-objects
diff-index
for-each-ref
hash-object
ls-files
merge-base
read-tree
rev-list
rev-parse
show-ref
symbolic-ref
update-index
update-ref
verify-pack
write-tree

Guides

gitattributes
Everyday Git
Glossary
githooks
gitignore
gitmodules
Revisions
Tutorial
Workflows

常用环境配置

在命令提示符号中,显示当前 GIT 分支

Display git branch in bash prompt

# 方法一:
export PS1="\\w\$(__git_ps1 '(%s)') \$ "

# 方法二:
parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\n$ "

# 注意事项:
#   1. 不管使用那种方法都要注意“\$”的存在,这用于防止命令被提前执行。否则,当切换到其他目
#      时,分支名不会发生改变;

参考文献

Git/Download for Linux and Unix
BLFS/Git-2.9.3