Git(一)——基礎概要

CentOS 安裝最新版本Git

yum 源倉庫里的 Git 版本更新不及時,最新版本的 Git 是 1.8.3.1,想要安裝最新版本的的 Git,只能下載源碼進行安裝。

yum info git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name        : git
Arch        : x86_64
Version     : 1.8.3.1
Release     : 14.el7_5
Size        : 4.4 M
Repo        : updates/7/x86_64
Summary     : Fast Version Control System
URL         : http://git-scm.com/
License     : GPLv2
Description : Git is a fast, scalable, distributed revision control system with an
            : unusually rich command set that provides both high-level operations
            : and full access to internals.
            :
            : The git rpm installs the core tools with minimal dependencies.  To
            : install all git packages, including tools for integrating with other
            : SCMs, install the git-all meta-package.

git已經發布的版本地址https://github.com/git/git/releases

image.png

依賴庫安裝

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install  gcc perl-ExtUtils-MakeMaker

卸載低版本的 Git

yum remove git

下載新版的 Git 源碼包

wget https://codeload.github.com/git/git/tar.gz/v2.18.0

解壓文件

tar -xzvf v2.18.0  -C ~/app/

安裝git

cd ~/app/git-2.18.0
make prefix=/usr/local/git all
make prefix=/usr/local/git install

添加到環境變量

echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc

查看版本

git --version
#git version 2.18.0

配置用戶信息

  1. git config --system : 為整個系統配置倉庫的通用配置,配置信息在/etc/gitconfig文件(用--system配置的信息,該Linux系統下的所有用戶都可使用)
  2. git config --global: 為當前用戶配置倉庫的通用配置,配置信息在/.gitconfig或/.config/git/config文件(配置在當前用戶下信息,在guest用戶下不可使用)
  3. git config --local: --local 參數可以缺省為當前倉庫配置信息,配置信息在當前倉庫的.git/config文件中。

具體配置用戶信息:

git config --system/--global/ --local user.email "you@example.com"
git config --system/--global/ --local user.name "Your Name"

查看配置清單

 git config --local -l #查看倉庫級的配置清單
 git config --global --list #查看全局級的配置清單
git config --system -l # 查看系統級的配置清單

配置全局忽略文件

定義Git全局的 .gitignore 文件
除了可以在項目中定義 .gitignore 文件外,還可以設置全局的git .gitignore文件來管理所有Git項目的行為。這種方式在不同的項目開發者之間是不共享的,是屬于項目之上Git應用級別的行為。這種方式也需要創建相應的 .gitignore 文件,可以放在任意位置。然后在使用以下命令配置Git:

# git config --global core.excludesfile ~/.gitignore

首先要強調一點,這個文件的完整文件名就是".gitignore",注意最前面有個“.”。一般來說每個Git項目中都需要一個“.gitignore”文件,這個文件的作用就是告訴Git哪些文件不需要添加到版本管理中。

修改git默認編輯器為Vim

linux中的git默認的編輯器nano,nano進行編輯提交的頁面,退出方法為:Ctrl + X然后輸入y再然后回車,就可以退出了
如果你想把默認編輯器nano換成git
方法一、在GIT配置中設置 core.editor: git config --global core.editor vim
方法二、修改.gitconfig文件。在core中添加editor = vim。如此以后在使用git的時候就自動使用vim作為編輯器

創建SSH Key

$ ssh-keygen -t rsa -C "youremail@example.com"

密鑰類型可以用 -t 選項指定。如果沒有指定則默認生成用于SSH-2的RSA密鑰。這里使用的是rsa。
同時在密鑰中有一個注釋字段,用-C來指定所指定的注釋,可以方便用戶標識這個密鑰,指出密鑰的用途或其他有用的信息。所以在這里輸入自己的郵箱或者其他都行。
輸入完畢后程序同時要求輸入一個密語字符串(passphrase),空表示沒有密語。接著會讓輸入2次口令(password),空表示沒有口令。3次回車即可完成當前步驟。

$ ssh-keygen -t rsa -C "yangyucug@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/baxiang/.ssh/id_rsa): 
Created directory '/home/baxiang/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/baxiang/.ssh/id_rsa.
Your public key has been saved in /home/baxiang/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Y4bxF3Aylak4SjOgmDnLaQODZFFPBHp8fuKbWkUTyYM yangyucug@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
| .ooooo.=.oo     |
| o+ oE +.=o      |
|== + o.+...      |
|X . * ++o  .     |
|o+.. *.+S .      |
|.=  o +o o       |
|. .  o           |
|    . o          |
|   ..o           |
+----[SHA256]-----+
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容