1.名詞解釋
fork:意思是從別人的代碼庫中復(fù)制一份到你自己的代碼庫钥组,與普通的復(fù)制不同撼嗓,fork包含了原有庫中的所有提交記錄狭瞎,fork后這個代碼庫是完全獨立的细移,屬于你自己,你可以在自己的庫中做任何修改熊锭,當(dāng)然也可以通過Pull Request向原來的庫提交合并請求弧轧。
watch: 相當(dāng)于收藏,關(guān)注后碗殷,代碼庫有新的commit, 你就會收到通知精绎。
star: 相當(dāng)于關(guān)注,方便下次查找作者的項目锌妻。
2.git 指令
3.遠(yuǎn)程數(shù)據(jù)庫代乃、本地數(shù)據(jù)庫
- 分支: Merge分支 Topic分支
Merge分支是為可以隨時發(fā)布release而創(chuàng)建的分支,它還能作為Topic分支的源分支使用仿粹。
Topic分支是為了開發(fā)新功能或修復(fù)Bug等任務(wù)而創(chuàng)建的分支搁吓,若要同時進行多個的任務(wù),請創(chuàng)建多個Topic分支吭历。
指令學(xué)習(xí)
git init
在桌面創(chuàng)建一個文件(lianxi)擎浴,在此路徑下創(chuàng)建一個空的git本地倉庫
Initialized empty Git repository in /Users/ML/Desktop/lianxi/.git/
在lianxi
下創(chuàng)建一個xxx.txt
文件,然后提交
git add xxx.tex
git commit -m "first commit"
[master (root-commit) 5389ca9] first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 xxx.txt
創(chuàng)建名為issue1的分支
git branch issue1
不指定參數(shù)直接執(zhí)行branch命令的話,可以顯示分支列表毒涧,前面有*的就是現(xiàn)在的分支
issue1
* master
若要在新建的issue1分支進行提交贮预,需要切換到issue1分支
切換到issue1分支
git checkout issue1
Switched to branch 'issue1'
在checkout命令中指定 -b選項執(zhí)行贝室,可以創(chuàng)建分支并進行切換
git checkout -b <brabch>
在切換到issue1分支的狀態(tài)下提交,歷史記錄會被記錄到issue1分支仿吞,在xxx.txt添加add命令說明后再提交(add 把變更錄入到索引中)
git add xxx.txt
git commit -m "添加add的說明"
[issue1 a1fa976] 添加add的說明
1 file changed, 1 insertion(+)
向master分支合并issue1分支的修改滑频, 執(zhí)行marge命令以合并分支
git marge <commit>
該命令將指定分支導(dǎo)入到HEAD指定的分支,先切換master分支唤冈,然后把issue1分支導(dǎo)入到master分支
git checkout master
Switched to branch 'master'
git merge issue1
Updating 5389ca9..a1fa976
Fast-forward
xxx.txt | 1 +
1 file changed, 1 insertion(+)
既然issue1分支的內(nèi)容已經(jīng)順利地合并到master分支了峡迷,現(xiàn)在可以將其刪除了
git branch -d issue1
Deleted branch issue1 (was a1fa976).
接下來創(chuàng)建2個分支來嘗試并行操作
首先創(chuàng)建issue2分支和issue3分支,并切換到issue2分支
git branch issue2
git branch issue3
git checkout issue2
* issue2
issue3
master
在issue2分支的xxx.txt 添加commit命令的說明提交
git add xxx.txt
git commit -m"這是說明"
[issue2 af79123] 這是說明
1 file changed, 1 insertion(+)
接著你虹,切換到issue3分支
git checkout issue3
git add xxx.txt
git commit -m "說明"
這樣绘搞,添加commit的說明的操作,和添加pull的說明的操作就并行進行了傅物。
解決合并的沖突
把issue2分支和issue3分支的修改合并到master
切換master分支后夯辖,與issue2分支合并
git checkout master
git merge issue2
Updating b2b23c4..8f7aa27
Fast-forward
xxx.txt | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
接著合并issue3分支
git merge issue3
Auto-merging myfile.txt
CONFLICT (content): Merge conflict in myfile.txt
Automatic merge failed; fix conflicts and then commit the result.
自動合并失敗,由于在同一行進行了修改董饰,所以產(chǎn)生了沖突蒿褂,這時xxx.txt內(nèi)容如上
在發(fā)生沖突的地方,git生成了內(nèi)容的差異卒暂,請做一下修改
然后重新提交
用rebase合并
合并issue3的時候啄栓,使用rebase可以使提交的歷史記錄顯得更簡介,現(xiàn)在暫時取消剛才的合并
git reset --hard HEAD~
切換到issue3分支后也祠,對master執(zhí)行rebase
git checkout issue3
git rebase master
和merge時的操作相同昙楚,修改在xxx.txt發(fā)生沖突的部分。
rebase的時候诈嘿,修改沖突后的提交不是使用commit命令堪旧,而是執(zhí)行rebase命令指定 --continue選項。若要取消rebase永淌,指定 --abort選項
git add xxx.txt
git rebase --continue
rebase的時候崎场,修改沖突后的提交不是使用commit命令佩耳,而是執(zhí)行rebase命令指定 --continue選項遂蛀。若要取消rebase,指定 --abort選項
標(biāo)簽
添加標(biāo)簽
git tag <tagname>
查看標(biāo)簽列表
git tag
如果在log命令添加--decorate選項執(zhí)行干厚,可以顯示包含標(biāo)簽資料的歷史記錄
git log --decorate
commit 163f3c574865c36b9216d5bf9bbfd190d60a067b (HEAD -> issue3, tag: apple, master)
Merge: a1fa976 af79123
Author: shenyuanjiang <1223551803@qq.com>
Date: Fri Feb 2 10:13:05 2018 +0800
解決沖突后的提交
commit af791230eccc82a26eac60f3bae94c1fff9e06f8 (issue2)
Author: shenyuanjiang <1223551803@qq.com>
Date: Fri Feb 2 09:27:11 2018 +0800
這是說明
commit a1fa976a50f3157283c647ed1612f0cae054d3ba
Author: shenyuanjiang <1223551803@qq.com>
Date: Thu Feb 1 13:10:57 2018 +0800
說明
commit 5389ca9f8aad16a11e6cfd53cc11e0a46a476edb
Author: shenyuanjiang <1223551803@qq.com>
Date: Thu Feb 1 11:55:52 2018 +0800
添加注釋標(biāo)簽
git tag -a <tagname>
標(biāo)簽列表
git tag -n
刪除標(biāo)簽
git tag -d <tagname>
改寫提交
git revert HEAD
另加: git log
a42e94c238dcb1ede23c2f73668ab0bace5fd49b
指的是版本號SHA1計算出來的一個非常大的數(shù)字李滴,用十六進制表示