Git遠(yuǎn)程版本庫(kù)
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),都昌企業(yè)網(wǎng)站建設(shè),都昌品牌網(wǎng)站建設(shè),網(wǎng)站定制,都昌網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,都昌網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
===============================================================================
概述:
===============================================================================
1.分布式版本控制系統(tǒng)
★基于的是網(wǎng)絡(luò)協(xié)議
http,https,ssh,git
2.克隆操作
★git clone
★原始版本庫(kù)存儲(chǔ)在 refs/heads/
3.git 服務(wù)器
★協(xié)議
本地協(xié)議(local)、HTTP/HTTPS協(xié)議、SSH協(xié)議、Git協(xié)議
☉本地協(xié)議
URL:
/path/to/repo.git
file:///path/to/repo.git
☉Git協(xié)議:由git-daemon程序提供,監(jiān)聽在tcp的9418端口;僅支持“讀”操作,無任何認(rèn)證功能(支持開放式的開源項(xiàng)目);
URL:
git://host/path/to/repo.git
git://host/~user/path/to/repo.git
☉SSH協(xié)議
URL:
ssh://[USER@]host[:port]/path/to/repo.git
ssh://[USER@]host[:port]/~USERNAME/path/to/repo.git
URL2:
[USER@]hostpath/torepo.git
☉HTTP/HTTPS協(xié)議
1.6.5-:?jiǎn)?http 協(xié)議
1.6.6+:智能 http 協(xié)議 (讀/寫/認(rèn)證)
URL:
http://host/path/to/repo.git
演示1:本地協(xié)議
[root@node1?~]#?git?clone?file:///root/taotao/?/root/huihui Cloning?into?'/root/huihui'... remote:?Enumerating?objects:?32,?done. remote:?Counting?objects:?100%?(32/32),?done. remote:?Compressing?objects:?100%?(23/23),?done. remote:?Total?32?(delta?8),?reused?0?(delta?0) Receiving?objects:?100%?(32/32),?done. Resolving?deltas:?100%?(8/8),?done. [root@node1?~]#?cd?/root/huihui/ [root@node1?huihui]#?ls first.sh??INSTALL??my.txt??readmin??second.sh??subdir [root@node1?huihui]#?cd?.git/ [root@node1?.git]#?ls branches??config??description??HEAD??hooks??index??info??logs??objects??packed-refs??refs [root@node1?.git]#?tree?refs/ refs/ ├──?heads │???└──?master??#實(shí)際上只clone的master分支 ├──?remotes???#遠(yuǎn)程跟蹤分支 │???└──?origin │???????└──?HEAD?#指向master分支 └──?tags 4?directories,?2?files [root@node1?~]#?tree?/root/taotao/.git/refs/ /root/taotao/.git/refs/ ├──?heads │???├──?dev │???├──?fotfix │???└──?master └──?tags 2?directories,?3?files
1.分布式版本控制系統(tǒng)
★遠(yuǎn)程版本庫(kù)
定義在配置文件中的一個(gè)實(shí)體;
[remote "NAME"]
☉由兩部分組成:
第一部分:URL
第二部分:refspec,定義一個(gè)版本庫(kù)與其他版本庫(kù)的名稱空間的映射關(guān)系;
☉語法格式:
+source:destination(本地分支和映射的目標(biāo)分支)
? ? ? ?refs/heads/NAME:本地分支
? ? ? ?refs/remotes/NAME:遠(yuǎn)程跟蹤分支
eg:
? ? ?[remote "publish"]
? ? ?url=http://HOST/pub/repo_name.git
? ? ?push= +refs/heads/*:refs/remotes/origin/*
顯示樣子:
? ? ?remote.publish.url
? ? ?remote.publish.push
?★git remote? 命令可管理遠(yuǎn)程倉(cāng)庫(kù)
git協(xié)議演示:
在node2服務(wù)器上安裝git服務(wù)器,并啟動(dòng)服務(wù)
[root@node2~]#?yum?install?git-daemon [root@node1?huihui]#?rpm?-ql?git-daemon /usr/lib/systemd/system/git.socket????#為一個(gè)瞬時(shí)守護(hù)進(jìn)程,可以直接啟動(dòng) /usr/lib/systemd/system/git@.service /usr/libexec/git-core/git-daemon /usr/share/doc/git-daemon-1.8.3.1 /usr/share/doc/git-daemon-1.8.3.1/git-credential-cache--daemon.html /usr/share/doc/git-daemon-1.8.3.1/git-credential-cache--daemon.txt /usr/share/doc/git-daemon-1.8.3.1/git-daemon.html /usr/share/doc/git-daemon-1.8.3.1/git-daemon.txt /usr/share/man/man1/git-credential-cache--daemon.1.gz /usr/share/man/man1/git-daemon.1.gz /var/lib/git???#git倉(cāng)庫(kù)的存放位置,相當(dāng)于根目錄 [root@node2?~]#?cat?/usr/lib/systemd/system/git@.service [Unit] Description=Git?Repositories?Server?Daemon Documentation=man:git-daemon(1) [Service] User=nobody?????????????????????????????????#?修改?--base-path?后的路徑可以改變git倉(cāng)庫(kù)的根目錄 ExecStart=-/usr/libexec/git-core/git-daemon?--base-path=/var/lib/git?--export-all?--user-path=public_git?--syslog?--inetd?--verbose StandardInput=socket #啟動(dòng)服務(wù),并查看tcp的端口9418 [root@node2?~]#?systemctl?start?git.socket [root@node2?~]#?ss?-tnl?|grep?9418 LISTEN?????0??????128?????????:::9418????????????????????:::*
2. 在nod2遠(yuǎn)程服務(wù)器上的git根目錄下創(chuàng)建一個(gè)裸倉(cāng)庫(kù),無需工作目錄
[root@node2?~]#?cd?/var/lib/git/ [root@node2?git]#?git?init?--bare?myproject.git 初始化空的?Git?版本庫(kù)于?/var/lib/git/myproject.git/ [root@node2?git]#?ls?myproject.git/ branches??config??description??HEAD??hooks??info??objects??refs
3. 在node1節(jié)點(diǎn)克隆node2節(jié)點(diǎn)的遠(yuǎn)程倉(cāng)庫(kù)
[root@node1?~]#?git?clone?git://192.168.0.102/myproject.git Cloning?into?'myproject'... warning:?You?appear?to?have?cloned?an?empty?repository. [root@node1?myproject]#?ls?-a .??..??.git [root@node1?myproject]#?git?config?-l user.name=watao user.email=wangzhangtao@pachiratech.com core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=git://192.168.0.108/myproject.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master
http協(xié)議演示:
1.安裝httpd,確保有alias,env和cgi模塊
[root@node2~]#?yum?install?httpd #?確保有如下3個(gè)模塊 [root@node2?~]#?httpd?-M?|grep?-Ei?"\<(alias|cgi|env)" ?alias_module?(shared) ?env_module?(shared) ?cgi_module?(shared)
2.創(chuàng)建裸倉(cāng)庫(kù),并修改屬組和屬主為apache用戶
[root@node2?~]#?mkdir?/var/www/git [root@node2?~]#?cd?/var/www/git/ [root@node2?git]#?ls [root@node2?git]#?git?init?--bare?testproject.git 初始化空的?Git?版本庫(kù)于?/var/www/git/testproject.git/ [root@node2?git]#?chown?-R?apache.apache?/var/www/git/ [root@node2?git]#?ll?/var/www/git/ 總用量?4 drwxr-xr-x?7?apache?apache?4096?11月??5?22:46?testproject.git
3.自定義虛擬主機(jī)
[root@node2?git]#?vim?/etc/httpd/conf/httpd.conf 注釋掉?DocumentRoot?"/var/www/html" [root@node2?git]#?vim?/etc/httpd/conf.d/git.conf ?<VirtualHost?*:80> ?????????ServerName?git.taotao.com ?????????SetEnv?GIT_PROJECT_ROOT?/var/www/git??#指明git根目錄位置 ?????????SetEnv?GIT_HTTP_EXPORT_ALL?#基于http協(xié)議導(dǎo)出所有功能 ?????????ScriptAlias?/git/?/usr/libexec/git-core/git-http-backend/??#定義別名的映射路徑 ?????????<Directory?"/usr/libexec/git-core/"> ?????????????????Options?ExecCGI?Indexes ?????????????????Require?all?granted ?????????</Directory> ?</VirtualHost> ? [root@node2?git]#?httpd?-t Syntax?OK
4.啟動(dòng)httpd服務(wù),并在node1節(jié)點(diǎn)克隆testproject.git倉(cāng)庫(kù)
[root@node2?git]#?systemctl?start?httpd [root@node2?git]#?ss?-tnl?|grep?80 LISTEN?????0??????128?????????:::80??????????????????????:::*? remote?helper?是?git?執(zhí)行?git?clone?http://..?所需要的一個(gè)模塊,而這個(gè)模塊坐落在?git-core?目錄里,并且這個(gè)模塊的文件名叫?git-remote-http [root@node1]#?cd?/usr/local/git/bin [root@node1?bin]#?ln?-s??/usr/libexec/git-core/git-remote-http?/usr/local/git/bin/git-remote-http [root@node1?bin]#?ln?-s??/usr/libexec/git-core/git-remote-https?/usr/local/git/bin/git-remote-https [root@node1?bin]#?ll total?67600 -rwxr-xr-x?126?root?root?15006529?Jul??3?22:26?git -rwxr-xr-x???2?root?root???162741?Jul??3?22:26?git-cvsserver -rwxr-xr-x???1?root?root???351673?Jul??3?22:26?gitk -rwxr-xr-x?126?root?root?15006529?Jul??3?22:26?git-receive-pack lrwxrwxrwx???1?root?root???????37?Nov??5?23:29?git-remote-http?->?/usr/libexec/git-core/git-remote-http lrwxrwxrwx???1?root?root???????38?Nov??5?23:29?git-remote-https?->?/usr/libexec/git-core/git-remote-https -rwxr-xr-x???2?root?root??8672864?Jul??3?22:26?git-shell -rwxr-xr-x?126?root?root?15006529?Jul??3?22:26?git-upload-archive -rwxr-xr-x?126?root?root?15006529?Jul??3?22:26?git-upload-pack [root@node1?~]#?git?clone?http://192.168.0.108/git/testproject.git Cloning?into?'testproject'... warning:?You?appear?to?have?cloned?an?empty?repository. [root@node1?~]#?cd?testproject/ [root@node1?testproject]#?ls?-a .??..??.git [root@node1?testproject]#?tree?.git/ .git/ ├──?branches ├──?config ├──?description ├──?HEAD ├──?hooks │???├──?applypatch-msg.sample │???├──?commit-msg.sample │???├──?fsmonitor-watchman.sample │???├──?post-update.sample │???├──?pre-applypatch.sample │???├──?pre-commit.sample │???├──?prepare-commit-msg.sample │???├──?pre-push.sample │???├──?pre-rebase.sample │???├──?pre-receive.sample │???└──?update.sample ├──?info │???└──?exclude ├──?objects │???├──?info │???└──?pack └──?refs ????├──?heads ????└──?tags 9?directories,?15?files [root@node1?testproject]#?git?config?-l user.name=watao user.email=wangzhangtao@pachiratech.com core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=http://192.168.0.108/git/testproject.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master
5.創(chuàng)建文件并上傳遠(yuǎn)程版本庫(kù),發(fā)現(xiàn)沒有權(quán)限
[root@node1?testproject]#?echo?"New?Line"?>?README [root@node1?testproject]#?cat?README New?Line [root@node1?testproject]#?git?add?README [root@node1?testproject]#?git?status On?branch?master No?commits?yet Changes?to?be?committed: ??(use?"git?rm?--cached?<file>..."?to?unstage) new?file:???README [root@node1?testproject]#?git?commit?-m?"v0.1" [master?(root-commit)?fb24458]?v0.1 ?1?file?changed,?1?insertion(+) ?create?mode?100644?README [root@node1?testproject]#? [root@node1?testproject]#? [root@node1?testproject]#?git?push?origin?master fatal:?unable?to?access?'http://192.168.0.108/git/testproject.git/':?The?requested?URL?returned?error:?403??#沒有權(quán)限
6.要想能夠做到允許用戶上傳操作,需要配置認(rèn)證訪問并開放訪問權(quán)限
#在node2節(jié)點(diǎn)開通http.receivepack [root@node2?testproject.git]#?git?config?http.receivepack?true [root@node2?testproject.git]#?git?config?-l core.repositoryformatversion=0 core.filemode=true core.bare=true http.receivepack=true #在node1節(jié)點(diǎn)再次上傳成功 [root@node1?testproject]#?git?push?origin?master Enumerating?objects:?3,?done. Counting?objects:?100%?(3/3),?done. Writing?objects:?100%?(3/3),?216?bytes?|?72.00?KiB/s,?done. Total?3?(delta?0),?reused?0?(delta?0) To?http://192.168.0.108/git/testproject.git ?*?[new?branch]??????master?->?master #在node2的遠(yuǎn)程版本庫(kù)查看已經(jīng)有提交對(duì)象 [root@node2?testproject.git]#?ls branches??config??description??HEAD??hooks??info??objects??refs [root@node2?testproject.git]#?cd?objects/ [root@node2?objects]#?ls 6b??dc??fb??info??pack [root@node2?objects]#?tree . ├──?6b │???└──?f181e7944f75a6411a13d94762118dafbc2cff ├──?dc │???└──?a7b9ab7d0a8f78dd357082f43ddd06c36533ee ├──?fb │???└──?244584596a111b649cc0ee0e4e0a554be60c68 ├──?info └──?pack
7.開放用戶認(rèn)證
[root@node2]#?cd?/etc/httpd/conf.d? [root@node2?conf.d]#?cat?git.conf? <VirtualHost?*:80> ????????ServerName?git.taotao.com SetEnv?GIT_PROJECT_ROOT?/var/www/git SetEnv?GIT_HTTP_EXPORT_ALL ScriptAlias?/git/?/usr/libexec/git-core/git-http-backend/ <Directory?"/usr/libexec/git-core/"> ????????Options?ExecCGI?Indexes Require?all?granted </Directory> <LocationMatch?"^/git/.*/git-receive-pack$"> ????????AuthType?Basic AuthName?"Private?Git?Repo" AuthUserFile?/etc/httpd/conf/.htpasswd Require?valid-user ????????</LocationMatch> </VirtualHost> [root@node2?conf.d]#?httpd?-t Syntax?OK [root@node2?~]#?systemctl?restart?httpd #node1節(jié)點(diǎn)刪除原來的目錄,重新克隆 [root@node1?~]#?rm?-fr?testproject/ [root@node1?~]#?git?clone?http://192.168.0.108/git/testproject.git Cloning?into?'testproject'... remote:?Counting?objects:?3,?done. remote:?Total?3?(delta?0),?reused?0?(delta?0) Unpacking?objects:?100%?(3/3),?done. [root@node1?~]#? [root@node1?~]#?cd?testproject/ [root@node1?testproject]#?ls README #顯示本地分支 [root@node1?testproject]#?git?show-branch? [master]?v0.1 #顯示遠(yuǎn)程分支 [root@node1?testproject]#?git?show-branch?-r !?[origin/HEAD]?v0.1 ?!?[origin/master]?v0.1 -- ++?[origin/HEAD]?v0.1 #?新添加一行 [root@node1?testproject]#?echo?"second?line"?>>?README? [root@node1?testproject]#?cat?README New?Line second?line [root@node1?testproject]#?git?add?README [root@node1?testproject]#?git?commit?-m?"v0.2" [master?a9bc92e]?v0.2 ?1?file?changed,?1?insertion(+)
在遠(yuǎn)程分支node2節(jié)點(diǎn)創(chuàng)建兩個(gè)用戶,并在node1本地上傳
[root@node2?~]#?htpasswd?-c?-m?/etc/httpd/conf/.htpasswd?tom New?password:? Re-type?new?password:? Adding?password?for?user?tom [root@node2?~]#?htpasswd?-m?/etc/httpd/conf/.htpasswd?jerry New?password:? Re-type?new?password:? Adding?password?for?user?jerry [root@node2?~]#?systemctl?reload?httpd #node1節(jié)點(diǎn)上傳需要輸入密碼 [root@node1?testproject]#?git?push?origin?master Enumerating?objects:?5,?done. Counting?objects:?100%?(5/5),?done. Writing?objects:?100%?(3/3),?254?bytes?|?42.00?KiB/s,?done. Total?3?(delta?0),?reused?0?(delta?0) Username?for?'http://192.168.0.108':?tom Password?for?'http://tom@192.168.0.108':? To?http://192.168.0.108/git/testproject.git ???fb24458..a9bc92e??master?->?master
分享文章:Git遠(yuǎn)程版本庫(kù)
鏈接地址:http://bm7419.com/article28/geiecp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、網(wǎng)站策劃、網(wǎng)站收錄、用戶體驗(yàn)、面包屑導(dǎo)航、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)