1毒费、Git基礎(chǔ)介紹
Git是一個(gè)開源的分布式版本控制系統(tǒng)恢筝,可以有效、高速的處理從很小到非常大的項(xiàng)目版本管理耍属。
安裝包:yum install git
Git分為以下區(qū):
工作區(qū):Working Directory
暫存區(qū):Staging Area矾兜,也叫index损趋,保存版本庫一次變化的元數(shù)據(jù),包括作者椅寺、郵箱浑槽、提交日期、日志等
版本庫:Repository返帕,或者對(duì)象庫-
Git的對(duì)象類型: .git/objects
塊(blob)對(duì)象:文件的每個(gè)版本表現(xiàn)為一個(gè)塊(blob)桐玻;
樹(tree)對(duì)象:一個(gè)目錄代表一層目錄信息;
提交的(commit)對(duì)象:用于保存版本庫一次變化的元數(shù)據(jù)荆萤,包括作者镊靴、郵箱、提交日期链韭、日志偏竟;每個(gè)提交對(duì)象都指定一個(gè)目錄樹對(duì)象;
標(biāo)簽(tag)對(duì)象:用于給一個(gè)特定對(duì)象一個(gè)易讀的名稱敞峭;
git reset:撤消此前的操作踊谋;
git reset --soft:相當(dāng)于撤銷了commit操作,此時(shí)index和工作目錄內(nèi)容不變旋讹,還是最新的版本殖蚕,只有對(duì)象庫中的內(nèi)容回到原來的版本;
git reset --mixed:相當(dāng)于撤銷commit和add操作骗村,此時(shí)index中的內(nèi)容也被撤銷了嫌褪,只有工作目錄中的內(nèi)容不變呀枢,還是最新的版本胚股;
git reset --hard:撤銷所有的操作,工作目錄中的內(nèi)容也回到原來的版本Git分支
git branch:列出裙秋、創(chuàng)建及刪除分支琅拌;
git branch BRANCH_NAME [START_COMMIT]
git branch -d BRANCH_NAME 刪除分支
git show-branch:查看分支及其相關(guān)的提交;
git checkout:創(chuàng)建和切換分支
git merge BRANCH_NAME:合并分支
git log:查看提交歷史
git tag:管理標(biāo)簽引用遠(yuǎn)程版本庫
git remote命令:管理遠(yuǎn)程倉庫摘刑;
git fetch:取回遠(yuǎn)程服務(wù)器的更新进宝;
git pull:取回遠(yuǎn)程服務(wù)器更新,而后與本地的指定分支合并枷恕;
git pull <遠(yuǎn)程主機(jī)名> <遠(yuǎn)程分支名>:<本地分支名>
git push:將本地的更新推送到遠(yuǎn)程主機(jī)党晋;
git push <遠(yuǎn)程主機(jī)名> <本地分支名>:<遠(yuǎn)程分支名>
示例:把某個(gè)目錄中的內(nèi)容納入到git來管理
[root@node1 app]#mkdir /app/app1
[root@node1 app]#cd /app/app1
[root@node1 app1]#vim README
test app project
[root@node1 app1]#git init #在當(dāng)前目錄下執(zhí)行此命令進(jìn)行g(shù)it初始化,就會(huì)把當(dāng)前目錄app1納入git來管理了
Initialized empty Git repository in /app/app1/.git/
[root@node1 app1]#ls -a #被git管理的目錄會(huì)有一個(gè).git的目錄
. .. .git README
[root@node1 app1]#tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── info
│ └── exclude
├── objects #所有被git追蹤的內(nèi)容將來都要放在此目錄下做為一個(gè)對(duì)象存在,保存的時(shí)候會(huì)對(duì)內(nèi)容進(jìn)行哈希運(yùn)算未玻,將哈希運(yùn)算的結(jié)果當(dāng)成文件名灾而,保存在對(duì)象目錄下,根緩存系統(tǒng)很相似
│ ├── info
│ └── pack
└── refs #記錄某一個(gè)時(shí)刻目錄內(nèi)容發(fā)生改變扳剿,這些有記錄的符號(hào)鏈接存放在此目錄下
├── heads
└── tags
[root@node1 app1]#git add README #將此文件保存到暫存區(qū)
[root@node1 app1]#tree .git/
.git/
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── objects
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382 #發(fā)現(xiàn)在對(duì)象目錄中增加了一個(gè)文件就是READM文件
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
[root@node1 app1]#mkdir examples src
[root@node1 app1]#ls
examples README src
[root@node1 app1]#vim examples/test
test example
[root@node1 app1]#git add . #將當(dāng)前目錄app1中的內(nèi)容全部保存至index
[root@node1 app1]#tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── objects
│ ├── 6c
│ │ └── 1792a38f86402e3560a3255beb63ac452b200e #又新增加了一個(gè)文件旁趟,也就是examples目錄下的test文件
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382 #發(fā)現(xiàn)此時(shí)還沒有記錄目錄的層級(jí)結(jié)構(gòu),只記錄了目錄中的文件
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
[root@node1 app1]#git config --global user.name magedu #在提交之前需要設(shè)置個(gè)人的信息庇绽,用戶名和郵箱等锡搜,不然每次提交之前都會(huì)提示輸入個(gè)人信息
[root@node1 app1]#git config --global user.email mage@magedu.com
[root@node1 app1]#git config --global --list
user.name=magedu
user.email=mage@magedu.com
[root@node1 app1]#git commit -m "initial version" #提交的時(shí)候需要指明一些描述信息,比如提交的是個(gè)初始版本
[root@node1 app1]#tree .git/ #發(fā)現(xiàn)多了三個(gè)對(duì)象文件瞧掺,除了上面兩個(gè)外耕餐,一個(gè)是app1根目錄,一個(gè)是example目錄夸盟,另外一個(gè)是提交本身蛾方,src因?yàn)槔锩鏇]有文件,所以目錄結(jié)構(gòu)并沒有被保存
.git/
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── logs
│ ├── HEAD
│ └── refs
│ └── heads
│ └── master
├── objects
│ ├── 6c
│ │ └── 1792a38f86402e3560a3255beb63ac452b200e
│ ├── 7f
│ │ └── b9eb1f385cb2b5fb5904e8b231436eae8ba78c
│ ├── 9c
│ │ └── 73b081ff7b864633f6f2177cee890425efd7bd
│ ├── a6
│ │ └── 057071df2675a95751ea08bbbf72f6f91214ff
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382
│ ├── info
│ └── pack
└── refs
├── heads
│ └── master
└── tags
[root@node1 app1]#git log #查看提交歷史
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c #在這里我們可以看到提交本身也是一個(gè)對(duì)象文件上陕,會(huì)保存到對(duì)象庫中
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app1]#rm -rf * #刪除該目錄下的所有內(nèi)容
[root@node1 app1]#ls -a
. .. .git
[root@node1 app1]#git checkout #從對(duì)象庫中檢出
D README
D examples/test
[root@node1 app1]#ls -a #發(fā)現(xiàn)檢出后并沒有真正的原因
. .. .git
[root@node1 app1]#git clone /app/app1 /tmp/app2 #需要克隆之后才能
真正的還原桩砰,所以我們?cè)趧?chuàng)建倉庫時(shí)可以自己從頭開始創(chuàng)建,就像上面
的創(chuàng)建過程一樣释簿,也可以克隆別人的倉庫中的內(nèi)容
Cloning into '/tmp/app2'...
done.
[root@node1 app1]#cd /tmp/app2/
[root@node1 app2]#ls -a #發(fā)現(xiàn)還原了
. .. examples .git README
[root@node1 app2]#tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── logs
│ ├── HEAD
│ └── refs
│ ├── heads
│ │ └── master
│ └── remotes
│ └── origin
│ └── HEAD
├── objects
│ ├── 6c
│ │ └── 1792a38f86402e3560a3255beb63ac452b200e
│ ├── 7f
│ │ └── b9eb1f385cb2b5fb5904e8b231436eae8ba78c
│ ├── 9c
│ │ └── 73b081ff7b864633f6f2177cee890425efd7bd
│ ├── a6
│ │ └── 057071df2675a95751ea08bbbf72f6f91214ff
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382
│ ├── info
│ └── pack
├── packed-refs
└── refs
├── heads
│ └── master #當(dāng)前目錄下已有文件的主分支
├── remotes #記錄下來當(dāng)前倉庫是從遠(yuǎn)程哪個(gè)倉庫克隆過來的
│ └── origin #表示起始倉庫
│ └── HEAD #指向它的最新一次提交
└── tags
[root@node1 app2]#git status
# On branch master #表示當(dāng)前在master分支上
nothing to commit, working directory clean #三個(gè)區(qū)域的內(nèi)容是一樣的
[root@node1 app2]#vim README
test app project
one line
[root@node1 app2]#git status #再次查看狀態(tài)
# On branch master
# Changes not staged for commit: #表示有一個(gè)改變沒有被提交
# (use "git add <file>..." to update what will be committed) #可以使用git add去更新索引并等待提交
# (use "git checkout -- <file>..." to discard changes in working directory) #可以使用git checkout去丟棄改變?cè)诠ぷ髂夸浿?#
# modified: README #更改的文件時(shí)README
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@node1 app2]#git add README #表示添加至?xí)捍鎱^(qū)并沒有提交
[root@node1 app2]#git status
# On branch master
# Changes to be committed: #表示現(xiàn)在可以進(jìn)行提交了
# (use "git reset HEAD <file>..." to unstage)#表示可以用git reset命令撤銷剛才的操作亚隅,也就是從暫存區(qū)中撤銷
#
# modified: README
#
[root@node1 app2]#git commit -m 'v0.2' #提交
[master 1d6adef] v0.2
1 file changed, 1 insertion(+)
[root@node1 app2]#git log #查看提交歷史,發(fā)現(xiàn)是上面是最新一次的提交
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean #告訴我們沒有什么需要提交的了庶溶,三個(gè)區(qū)域工作目錄煮纵、index、對(duì)象庫中又同步了
[root@node1 app2]#vim newfile #在工作目錄下創(chuàng)建一個(gè)新的文件
hello world
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m 'v0.3'
[master 4ba897e] v0.3
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log #可以看到最近三次提交
commit 4ba897eaf80b2b195da0b4a27fe2228c24779723
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:33:45 2017 +0800
v0.3
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git reset --soft 1d6adef3 #撤銷commit操作至第二
次提交偏螺,1d6adef3是第二次提交的對(duì)象文件的前幾個(gè)字符行疏,只要和其他
的提交能區(qū)別唯一就可以
[root@node1 app2]#git status #發(fā)現(xiàn)返回到最后一次提交之前的狀態(tài)了
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: newfile
#
[root@node1 app2]#git commit -m "v0.3.1" #再一次提交
[root@node1 app2]#git status
[root@node1 app2]#git log
commit fd87dc12f2aa5ac0ba46706158341ca2873270b3
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:41:33 2017 +0800
v0.3.1
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git reset --mixed 1d6adef3 #再次撤銷到第二次提交
[root@node1 app2]#git status #發(fā)現(xiàn)commit和add操作都被撤銷了
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# newfile
nothing added to commit but untracked files present (use "git add" to track)
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m "v3.0.2" #再次提交
[master 99797e0] v3.0.2
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log
commit 99797e0fea11a9ea899b5adb6a73d03fa05d3de1
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:45:24 2017 +0800
v3.0.2
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git reset --hard 1d6adef3 #再次撤銷至第二次提交
HEAD is now at 1d6adef v0.2
[root@node1 app2]#ls -a #發(fā)現(xiàn)連工作目錄中的文件也被撤銷了
. .. examples .git README
示例:如何添加分支
[root@node1 app2]#git branch --list #查看分支
* master
[root@node1 app2]#git branch stroy2 #添加分支
[root@node1 app2]#git branch stroy3
[root@node1 app2]#git branch --list #發(fā)現(xiàn)添加了兩個(gè)分支
* master #帶*表示當(dāng)前分支
stroy2
stroy3
[root@node1 app2]#ls .git/refs/heads/ #在此目錄下生成了三個(gè)文件,每個(gè)文件就是一個(gè)分支
master stroy2 stroy3
[root@node1 app2]#git checkout stroy2 #切換分支
Switched to branch 'stroy2'
[root@node1 app2]#git branch --list
master
* stroy2
stroy3
[root@node1 app2]#vim newfile
stroy 2
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m "stroy2.v0.1"
[stroy2 b39a485] stroy2.v0.1
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log
commit b39a48512bfd6ec7aea8cf6835dfee8d6fc1d644
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:58:06 2017 +0800
stroy2.v0.1
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git checkout master #切換回master分支
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
[root@node1 app2]#git branch --list
* master
stroy2
stroy3
[root@node1 app2]#git log #發(fā)現(xiàn)不同的分支上所看到的提交歷史是不一樣的
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#ls -a
. .. examples .git README
[root@node1 app2]#git branch --list
* master
stroy2
stroy3
[root@node1 app2]#git checkout stroy2
Switched to branch 'stroy2'
[root@node1 app2]#ls -a #我們發(fā)現(xiàn)不同的分支套像,它們的工作目錄是不同的
. .. examples .git newfile README
[root@node1 app2]#git checkout master #切換到master分支
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
[root@node1 app2]#git branch --list
* master
stroy2
stroy3
[root@node1 app2]#vim newfile #也創(chuàng)建一個(gè)和stroy2一樣名字的文件酿联,但內(nèi)容不同
master newfile
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m "v0.3"
[master 304af42] v0.3
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log #發(fā)現(xiàn)在不同分支上名字相同的文件也可以
提交,說明git內(nèi)部對(duì)所有對(duì)象的追蹤是根據(jù)內(nèi)容的哈希值識(shí)別的夺巩,而不
是根據(jù)文件名
commit 304af4289bc0cb3358d209edf68cd3ed1ddfbfa5
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 22:07:15 2017 +0800
v0.3
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
2贞让、在github上如何使用git命令從遠(yuǎn)程克隆一個(gè)倉庫
https://github.com 官方網(wǎng)站
[root@node1 network-scripts]#cd /app
[root@node1 app]#git clone https://github.com/happyfish100/fastdfs.git #在github上克隆一個(gè)倉庫
[root@node1 app]#cd fastdfs/ #發(fā)現(xiàn)在此工作目錄下也有.git目錄
[root@node1 fastdfs]#ls -a
. client conf fastdfs.spec HISTORY INSTALL php_client restart.sh storage tracker
.. common COPYING-3_0.txt .git init.d make.sh README.md stop.sh test
[root@node1 fastdfs]#git config --list
user.name=magedu
user.email=mage@magedu.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/happyfish100/fastdfs.git #遠(yuǎn)程工作目錄的url
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* #表示本地的工作目錄是從遠(yuǎn)程的origin分支取過來的,遠(yuǎn)程refs/remotes/origin/*分支下的所有內(nèi)容對(duì)應(yīng)的是本地分支的refs/heads/master分支下的所有內(nèi)容
branch.master.remote=origin #遠(yuǎn)程的master分支在本地表現(xiàn)為origin分支
branch.master.merge=refs/heads/master #本地的master分支的工作目錄是來自遠(yuǎn)程的origin分支的工作目錄
[root@node1 fastdfs]#ls .git/refs/remotes/origin/
HEAD
[root@node1 fastdfs]#ls .git/refs/heads/
master
3柳譬、在github上創(chuàng)建一個(gè)倉庫然后克隆到本地修改后再推到github上
在github上注冊(cè)一個(gè)賬號(hào)喳张,登錄后創(chuàng)建一個(gè)倉庫如下圖
克隆倉庫到本地進(jìn)行編輯
[root@node1 app]#git clone https://github.com/qilinzhicai/testrepos.git
Cloning into 'testrepos'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
[root@node1 app]#cd testrepos/ #進(jìn)入此工作目錄
[root@node1 testrepos]#ls -a
. .. .git README.md
[root@node1 testrepos]#vim myfile
hello this is my first github
[root@node1 testrepos]#git add myfile
[root@node1 testrepos]#git commit -m "githubv0.1"
[master bbd856a] githubv0.1
1 file changed, 1 insertion(+)
create mode 100644 myfile
[root@node1 testrepos]#git log
commit bbd856a7b732ff8ffe60fa24d40d87ec791aeb9a
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 22:41:34 2017 +0800
githubv0.1
commit 9336769479c41cf730fcb3788c5b799beedc609b
Author: qilinzhicai <34060909+qilinzhicai@users.noreply.github.com>
Date: Tue Nov 28 19:24:16 2017 +0800
Initial commit
[root@node1 testrepos]#git tag -a testapp-v0.1 bbd856 #給本次提交添加一個(gè)標(biāo)簽為testapp-v0.1
testapp-v0.1
#
# Write a tag message
# Lines starting with '#' will be ignored.
[root@node1 testrepos]#git tag --list
testapp-v0.1
[root@node1 testrepos]#git help tag
[root@node1 testrepos]#git help push
[root@node1 testrepos]#ls .git/refs/tags/ #標(biāo)簽存放在此目錄下
testapp-v0.1
[root@node1 testrepos]#git branch --list #當(dāng)前的分支是在master
* master
[root@node1 testrepos]#ls -a #在master分支下工作目錄中有如下內(nèi)容
. .. .git myfile README.md
[root@node1 testrepos]#git push --tags origin master #表示把本地的
maste分支上的工作目錄推到遠(yuǎn)程的origin分支上的工作目錄中,并加標(biāo)
簽美澳,因?yàn)檫h(yuǎn)程的master分支在本地表現(xiàn)為origin分支销部,所以要寫成origin
Username for 'https://github.com': qilinzhicai #要輸入guthub的賬號(hào)和密碼
Password for 'https://qilinzhicai@github.com':
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 413 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://github.com/qilinzhicai/testrepos.git
9336769..bbd856a master -> master
* [new tag] testapp-v0.1 -> testapp-v0.1
可以看到推送成功摸航,其他人就可以用pull把遠(yuǎn)程的倉庫取過來和本地的合并,也可以用fetch把遠(yuǎn)程倉庫的取過來和本地不合并
總結(jié):在這里我們所說的倉庫其實(shí)就是在一個(gè)分支上的一個(gè)工作目錄
4舅桩、搭建gitlib
gitlib是一個(gè)軟件忙厌,安裝此軟件后,可以提供一個(gè)web界面江咳,相當(dāng)于github一樣的web網(wǎng)站逢净,可以在此網(wǎng)站上創(chuàng)建倉庫,進(jìn)行和github一樣的操作
lftp 172.18.0.1:/pub/Sources/7.x86_64/gitlab> ls
-rw-r--r-- 1 0 0 345224324 Aug 21 09:10 gitlab-ce-7.14.3-ce.1.el7.x86_64.rpm
-rw-r--r-- 1 0 0 280689456 Aug 21 09:09 gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
lftp 172.18.0.1:/pub/Sources/7.x86_64/gitlab> get gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
280689456 bytes transferred in 4 seconds (70.11M/s)
[root@node1 app]#rpm -ivh ./gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
[root@node1 app]#rpm -ivh ./gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-8.8.3-ce.0.el7 ################################# [100%]
gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:
sudo gitlab-ctl reconfigure #下一步執(zhí)行此命令
gitlab: GitLab should be reachable at http://node1.magedu.com
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab:
gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme
gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
gitlab:
It looks like GitLab has not been configured yet; skipping the upgrade script.
[root@node1 app]#gitlab-ctl reconfigure
[root@node1 app]#gitlab-ctl help
[root@node1 app]#gitlab-ctl start #啟動(dòng)
ok: run: gitlab-workhorse: (pid 17791) 84s
ok: run: logrotate: (pid 17168) 120s
ok: run: nginx: (pid 17093) 126s
ok: run: postgresql: (pid 16942) 152s
ok: run: redis: (pid 16858) 158s
ok: run: sidekiq: (pid 17066) 134s
ok: run: unicorn: (pid 18149) 59s
[root@node1 app]#ss -nlt #發(fā)現(xiàn)打開了很多端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:8080 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
可以看到類似于github的界面了
5歼指、在github上使用ssh連接克隆或者push到遠(yuǎn)程倉庫的設(shè)置
使用ssh連接后不用每次都輸入賬號(hào)和密碼
[root@node1 app]#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)?
[root@node1 app]#cd
[root@node1 ~]#cd .ssh/
[root@node1 .ssh]#ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@node1 .ssh]#cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClFgU7bGSRFMmvFXLkb3hhMSCXkRIkaRLjNzk3lPw+AP1nWPGc343p6RprBTqsFLmOqCOjNtwH742PcTmy9WRYCzBlAAw5oTaHoU3EgmqDa43HuWJCl0f0rlaSNo2Vrj6db7e54g/nsz4+ur+icITot47JjgkT5DVpnEw88N33fYNvJJw6DVrfZn/96N0FmaECQXjXsCt5EuOnVH2/J2sOI7EecA+3/00QOdCvTrsuY4bkNAxd3jh+5EC+Xo3ONLtfx3D8ggMpf36nWG/WXWwzR1sPy7tVsLdRICd1k2SH/ul0fXFWACw84aB54XnHaBukxrAhf4nu3v9MJlvBBQWn root@node1.magedu.com
將以上公鑰的內(nèi)容復(fù)制到下圖的位置即可,注意要事先用自己的賬號(hào)登錄后才能進(jìn)行如下操作
最后添加的時(shí)候可能會(huì)跳轉(zhuǎn)至一個(gè)界面讓輸入登錄賬號(hào)的密碼
添加完后如下圖爹土,就可以基于ssh進(jìn)行g(shù)ithub上的遠(yuǎn)程倉庫了