天天看點

Git(分布式版本控制)

Git(分布式版本控制)

Git伺服器端

[[email protected] ~]# yum install -y git              ==>>安裝git

[[email protected] ~]# mkdir /var/git

[[email protected] ~]# git init /var/git/project --bare   ==>>建立一個空的git倉庫

初始化空的 Git 版本庫于 /var/git/project/

[[email protected] ~]# ls /var/git/project/

branches  config  description  HEAD  hooks  info  objects  refs

[[email protected] ~]# 

Git用戶端

    git指令表,克隆完倉庫之後要在倉庫目錄下執行git的相關指令

    clone:将遠端伺服器的倉庫克隆到本地

    config:修改git配置

    add:添加修改到暫存區 

    commit:送出修改到本地倉庫

    push:送出修改到遠端伺服器

1.Git安裝部署

[[email protected] ~]# yum install -y git

[[email protected] ~]# git clone [email protected]:/var/git/project   ==>>克隆倉庫到本地

[[email protected] ~]# cd project/

[[email protected] project]# git config --global user.email "[email protected]"  ==>>修改git配置,聲明自己的資訊,第一次操作需執行

[[email protected] project]# git config --global user.name "Your Nas"

[[email protected] project]# git status   ==>>檢視倉庫的資料動态

[[email protected] project]# git add .   ==>>将工作區的修改送出到暫存區

[r[email protected] project]# git commit -m "注釋"   ==>>将暫存區的修改送出到本地倉庫

[[email protected] project]# git config --global push.default simple   ==>>第一次上傳伺服器需要執行

[[email protected] project]# git push ==>>将本地倉庫上傳到伺服器

[[email protected] project]# git pull   ==>>将伺服器的更新部分同步到本地

[[email protected] project]# git log    ==>>檢視修改日志

[r[email protected] project]# git log --pretty=oneline  ==>>檢視修改了幾個版本

[[email protected] project]# git log --oneline      

[[email protected] project]# git reflog

------------------------------------------

    Windows可以安裝git和otrtoiseGit使用

------------------------------------------

[[email protected] project]# git reflog

[[email protected] project]# git log --oneline

65fd173  789 c

f50595e  456 c

d8ccca2  123 c

d11b274 add nfss sssssss

cd5a274 add nfss

9492653 add new.txt

a28e27c zhuhis

[[email protected] project]# git reset --hard f505   ==>>回到f50595e  456 c這個修改位置

2.Git 分支

    常見的分支規範如下:

    MASTER分支(MASTER是主分支,是代碼的核心)

    DEVELOP分支(DEVELOP最新開發成果的分支)

    RELEASE分支(為釋出新産品設定的分支)

    HOTFIX分支(為了修複軟體BUG缺陷的分支)

    FESATURE分支(為開發新功能設定的分支)

[[email protected] project]# git branch 分支名     ==>>建立分支

[[email protected] project]# git branch -v      ==>>檢視分支

[[email protected] project]# git checkout 分支名   ==>>切換分支

[root@web2 project]# git checkout master    ==>>合并到主分支之前,切換到主分支

[[email protected] project]# git merge 分支名        ==>>合并到主分支

Git伺服器

    基于SSH協定伺服器

    基于Git協定伺服器

    基于HTTP協定伺服器

1.基于SSH協定伺服器

伺服器安裝Git

[[email protected] ~]# yum install -y git              ==>>安裝git

[[email protected] ~]# mkdir /var/git

[[email protected] ~]# git init /var/git/project --bare   ==>>建立一個空的git倉庫

用戶端可以實作SSH免密登入

[[email protected] project]# ssh-keygen -f /root/.ssh/id_rsa -N ''    ==>>建立密鑰

[[email protected] project]# ssh-copy-id 192.168.2.100                ==>>将密鑰分發

2.基于Git協定伺服器

伺服器端

[[email protected] ~]# yum install -y git-daemon

[[email protected] ~]# git init --bare /var/git/base_git  ==>>建立版本庫

[[email protected] ~]# vim /usr/lib/systemd/system/[email protected]    ==>>修改路徑

ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/git --export-all --user-path=public_git --syslog --inetd --verbose

[[email protected] ~]# systemctl start git.socket 

用戶端

[[email protected] ~]# git clone git://192.168.2.100/base_git

3.基于HTTP協定伺服器

服務端

[[email protected] ~]# yum -y install httpd gitweb

[[email protected] ~]# vim +11 /etc/gitweb.conf     ==>>在11行添加内容

$projectroot="/var/git";

[ro[email protected] ~]# git init --bare /var/git/base_http   ==>>建立版本庫

初始化空的 Git 版本庫于 /var/git/base_http/

[[email protected] ~]# systemctl start httpd

用戶端圖形化界面通路

[[email protected] ~]# firefox http://192.168.2.100/git/

繼續閱讀