Git分佈式版本控制系統安裝、配置
一、Git簡介
Git是目前世界上最先進的分佈式版本控制系統,在處理各種項目時都十分高效,而且非常的高大上。
-
SVN是集中式版本控制系統,版本庫是集中放在中央服務器的,而幹活的時候,用的都是自己的電腦,所以首先要從中央服務器哪裏得到最新的版本,然後幹活,幹完後,需要把自己做完的活推送到中央服務器。而且集中式版本控制系統是必須聯網才能工作。
-
Git是分佈式版本控制系統,它就沒有中央服務器的,每個人的電腦就是一個完整的版本庫,這樣,工作的時候就不需要聯網了,因爲版本都是在自己的電腦上。
二、Git安裝
Centos7系統下的安裝過程
- Git的安裝,分爲使用yum安裝和下載git源碼編譯安裝。
- 源代碼安裝有很多好處,可以安裝最新的版本。
源碼安裝:
1、移除舊版本git
Centos自帶Git,7.x版本自帶git 1.8.3.1,安裝新版本之前需要使用yum remove git卸載
[root@localhost ~]# git --version ##查看git版本##
git version 1.8.3.1
[root@localhost ~]# yum remove git ##卸載自帶老版本git##
2、安裝git的依賴包
[root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
3、下載git源碼
[root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.7.3.tar.gz
4、解壓
[root@localhost ~]# tar -xvf git-2.7.3.tar.gz
5、配置編譯安裝
[root@localhost ~]# cd git-2.7.3 ##進入到git-2.7.3安裝目錄##
[root@localhost git-2.7.3]# make prefix=/root/git all
[root@localhost git-2.7.3]# make prefix=/usr/local/git install
6、配置環境變量
a、查看git安裝路徑:whereis git
[root@localhost git-2.7.3]# whereis git
git: /usr/local/git /usr/local/git/bin/git
b、配置環境變量: vi /etc/profile
export PATH=/usr/local/git/bin:$PATH:$MAVEN_HOME/bin
c、加載該配置:source /etc/profile
[root@localhost git-2.7.3]# source /etc/profile
d、查看版本號:git --version
[root@localhost git-2.7.3]# git --version
git version 2.7.3
注:可能會出現因爲系統時間不正確導致報錯
[root@localhost ~]# yum install -y ntp ntpdate ##安裝工具##
[root@localhost ~]# ntpdate cn.pool.ntp.org ##設置系統時間與網絡時間同步##
[root@localhost ~]# hwclock –systohc ##將系統時間寫入硬件時間##
Yum安裝:
[root@localhost ~]# yum install -y git
——————————————————————————————————————
Windows系統下的安裝視頻
三、Git使用解析
1、本地庫初始化
[root@localhost ~]# mkdir villian ##創建一個目錄作爲本地庫##
[root@localhost ~]# cd villian ##進入到該目錄對該目錄進行初始化##
[root@localhost villian]# git init ##對本地庫進行初始化##
初始化空的 Git 版本庫於 /root/villian/.git/
[root@localhost villian]# ls -a ##查看.git隱藏目錄##
. .. .git
[root@localhost villian]# cd .git/ ##.git目錄內屬於配置文件+子目錄,不可刪除不可亂修改##
[root@localhost .git]# ls
branches config description HEAD hooks info objects refs
2、設置簽名(一般設置系統級別即可)
- 項目級別/倉庫級別:僅在當前本地庫範圍內有效
[root@localhost villian]# git config user.name villian
[root@localhost villian]# git config user.email villian@163.com (郵箱可虛設)
信息保存目錄:villian/.git/config
[root@localhost villian]# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
name = villian
email = villian@163.com
——————————————————————————————————————
- 系統用戶級別,登錄當前操作系統的用戶範圍
[root@localhost villian]# git config --global user.name villian
[root@localhost villian]# git config --global user.email villian@163.com (郵箱可虛設)
信息保存目錄:~/.gitconfig (~家目錄)
[root@localhost ~]# cat .gitconfig
[user]
name = villian
email = villian@163.com
——————————————————————————————————————
級別優先級:
- 就近原則,項目級別優先於系統級別
- 二者都有時,則採用項目級別的簽名
- 只有系統用戶級別的簽名,就以系統級別簽名爲準
- 不允許出現二者都沒有