創(chuàng)建遠(yuǎn)程分支
現(xiàn)在有一個本地倉庫gitskills并已經(jīng)和遠(yuǎn)程倉庫git@github.com:fantianwen/gitskills.git相關(guān)聯(lián)伐割。
1谁帕、創(chuàng)建本地分支并推送到遠(yuǎn)程分支
創(chuàng)建本地分支
I:gitskills RadAsm$ git checkout -b dev
Switched to a new branch 'dev'
這樣就創(chuàng)建了本地分支“dev”并切換到了“dev”分支
將本地分支
dev
推送到成為遠(yuǎn)程倉庫的分支缚柏,名稱為dev
I:gitskills RadAsm$ git push origin dev:dev
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:fantianwen/gitskills.git
* [new branch] dev -> dev
如果發(fā)現(xiàn)這個遠(yuǎn)程分支
dev
我不想推送了个绍,刪除這個遠(yuǎn)程分支
I:gitskills RadAsm$ git push origin :dev
To git@github.com:fantianwen/gitskills.git
- [deleted] dev
這樣雹仿,這個遠(yuǎn)程分支dev
就已經(jīng)刪除了。
查看遠(yuǎn)程分支有哪些
I:gitskills RadAsm$ git branch -a
* dev
master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
可見玄组,現(xiàn)在遠(yuǎn)程分支有dev
和master
滔驾,并且當(dāng)前遠(yuǎn)程分支指針在master
上面谒麦。
2俄讹、他人獲取你的遠(yuǎn)程倉庫到本地并協(xié)同開發(fā)
他人希望在hellgit目錄下獲取gitskills這個遠(yuǎn)程倉庫
本地init
I:hellogit RadAsm$ git init
Initialized empty Git repository in /Users/RadAsm/hellogit/.git/
獲取遠(yuǎn)程倉庫
I:hellogit RadAsm$ git pull git@github.com:fantianwen/gitskills.git
remote: Counting objects: 23, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 23 (delta 5), reused 19 (delta 4), pack-reused 0
Unpacking objects: 100% (23/23), done.
From github.com:fantianwen/gitskills
* branch HEAD -> FETCH_HEAD
注意使用git pull
去獲取,最好不要用git clone
绕德。
你希望查看當(dāng)前倉庫有哪些分支(當(dāng)然患膛,你也希望能夠知道遠(yuǎn)程倉庫有哪些分支,這樣耻蛇,你好切換分支)
I:hellogit RadAsm$ git branch -a
* master
你會發(fā)現(xiàn)無論是git branch
還是git branch -a
,都只是上面的結(jié)果顯示踪蹬。
當(dāng)然,這是********協(xié)同開發(fā)********,你的上司(或者同伴)會告訴你遠(yuǎn)程倉庫的分支有哪些臣咖。這時候跃捣,你的上司告訴你,遠(yuǎn)程倉庫有分支dev
實時更新遠(yuǎn)程倉庫的情況(不光是內(nèi)容夺蛇,還有分支等情況)pull到本地,這時候疚漆,你使用
git pull
fatal: No remote repository specified. Please, specify either a URL or a
remote name from which new revisions should be fetched.
你需要將本地倉庫和遠(yuǎn)程倉庫相關(guān)聯(lián)
I:hellogit RadAsm$ git remote add origin git@github.com:fantianwen/gitskills.git
再使用
git pull
I:hellogit RadAsm$ git pull
From github.com:fantianwen/gitskills
* [new branch] dev -> origin/dev
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
這樣,你會發(fā)現(xiàn)遠(yuǎn)程倉庫中有哪些分支刁赦,并且都已經(jīng)實時更新了娶聘。
這樣,你需要在遠(yuǎn)程分支上
dev
上進(jìn)行開發(fā)甚脉,這樣丸升,你要做出切換
I:hellogit RadAsm$ git checkout -b dev origin/dev
Branch dev set up to track remote branch dev from origin.
Switched to a new branch 'dev'
這樣,你在本地開發(fā)完之后牺氨,就把本地
dev
推動送遠(yuǎn)程的dev
git push origin dev
tag標(biāo)簽管理
繼續(xù)按照上面的搭建的兩個本地倉庫gitskills和hellogit相關(guān)聯(lián)的情況下狡耻。
(所謂標(biāo)簽其實就是一個可以發(fā)布的一個穩(wěn)定版本。)
1猴凹、本地tag標(biāo)簽(在gitskills本地倉庫中)
創(chuàng)建本地標(biāo)簽
I:gitskills RadAsm$ git tag v1.1
這樣打的tag是將最近一次commit
的作為tag酝豪。
查看本地標(biāo)簽
I:gitskills RadAsm$ git tag
v1.1
結(jié)果顯示有一個標(biāo)簽。
當(dāng)然精堕,你希望把某個歷史的commit打上標(biāo)簽
I:gitskills RadAsm$ git log --pretty=oneline --abbrev-commit
d29f4d0 fix bug issue!
81ff668 merge dev1 with no-ff
7b34ae1 dev1的修改
99eebef 分支管理策略
7973593 confict merge
1bdba94 master的提交
87d4d53 branch feature1
69f373b branch test
c62f37e Initial commit
使用git log --pretty=oneline --abbrev-commit
命令打印出所有的commit的歷史信息(這個指令有點(diǎn)難記啊~)
然后對某個歷時commit打上tag孵淘,譬如我要在1bdba94 master的提交
這個commit上打上v2.0的tag。
I:gitskills RadAsm$ git tag v2.0 1bdba94
然后使用git tag查看tag情況
I:gitskills RadAsm$ git tag
v1.1
v2.0
當(dāng)然歹篓,誰知道你打上的tag包含什么樣的信息瘫证,你需要為這個tag做出信息注釋揉阎。
I:gitskills RadAsm$ git tag -a v3.0 -m "this is a steady tag with annotation" 7973593
查看某個tag
I:gitskills RadAsm$ git show v3.0
tag v3.0
Tagger: RadAsm <twfan_09@hotmail.com>
Date: Fri Sep 25 10:06:37 2015 +0800
this is a steady tag with annotation
commit 79735933ead1f1c95e9c150a55ecfde2fd11f771
Merge: 1bdba94 87d4d53
Author: RadAsm <twfan_09@hotmail.com>
Date: Mon Sep 21 13:42:46 2015 +0800
confict merged
刪除標(biāo)簽
I:gitskills RadAsm$ git tag -d v1.1
Deleted tag 'v1.1' (was d29f4d0)
2、將本地tag推送上遠(yuǎn)程
git push origin
I:gitskills RadAsm$ git push origin v2.0
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:fantianwen/gitskills.git
* [new tag] v2.0 -> v2.0
如果希望將本地的所有的tag都推送到遠(yuǎn)程
git push origin --tags
協(xié)同開發(fā)下背捌,你的同伴在本地獲取遠(yuǎn)程倉庫的tag
I:hellogit RadAsm$ git pull
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), done.
From github.com:fantianwen/gitskills
* [new tag] v3.0 -> v3.0
Already up-to-date.
這樣毙籽,你就獲取了v3.0的tag。
3毡庆、刪除遠(yuǎn)程倉庫中的tag
先將本地的該tag刪除
I:gitskills RadAsm$ git tag -d v2.0
Deleted tag 'v2.0' (was 1bdba94)
進(jìn)行遠(yuǎn)程倉庫的刪除
I:gitskills RadAsm$ git push origin :refs/tags/v2.0
To git@github.com:fantianwen/gitskills.git
- [deleted] v2.0
這樣坑赡,遠(yuǎn)程的tag v2.0也刪除了。
這時候么抗,你的同伴使用
git pull
進(jìn)行更新毅否,當(dāng)然,她在你刪除遠(yuǎn)程tag之前進(jìn)行了更新蝇刀,本地已經(jīng)有了tag(假設(shè)這個tag是v3.0)螟加。你使用git tag
進(jìn)行查看
I:hellogit RadAsm$ git tag
v1.0
v3.0
你會發(fā)現(xiàn),遠(yuǎn)程已經(jīng)刪除的v3.0本地還在吞琐。是的捆探,你需要手動刪掉tag(使用git pull
沒有效果)。