這篇文章記錄我在使用git的過(guò)程中碰到遠(yuǎn)程分支和tag的相關(guān)內(nèi)容,提綱:
查看遠(yuǎn)程分支加上-a參數(shù)可以查看遠(yuǎn)程分支,遠(yuǎn)程分支會(huì)用紅色表示出來(lái)(如果你開了顏色支持的話): $ git branch -a master remote tungway v1.52 * zrong remotes/origin/master remotes/origin/tungway remotes/origin/v1.52 remotes/origin/zrong 刪除遠(yuǎn)程分支和tag在Git v1.7.0 之后,可以使用這種語(yǔ)法刪除遠(yuǎn)程分支: $ git push origin --delete <branchName> 刪除tag這么用: git push origin --delete tag <tagname> 否則,可以使用這種語(yǔ)法,推送一個(gè)空分支到遠(yuǎn)程分支,其實(shí)就相當(dāng)于刪除遠(yuǎn)程分支: git push origin :<branchName> 這是刪除tag的方法,推送一個(gè)空tag到遠(yuǎn)程tag: git tag -d <tagname> git push origin :refs/tags/<tagname> 兩種語(yǔ)法作用完全相同。 刪除不存在對(duì)應(yīng)遠(yuǎn)程分支的本地分支假設(shè)這樣一種情況:
使用下面的代碼查看b1的狀態(tài): $ git remote show origin * remote origin Fetch URL: git@github.com:xxx/xxx.git Push URL: git@github.com:xxx/xxx.git HEAD branch: master Remote branches: master tracked refs/remotes/origin/b1 stale (use 'git remote prune' to remove) Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date) 這時(shí)候能夠看到b1是stale的,使用 更簡(jiǎn)單的方法是使用這個(gè)命令,它在fetch之后刪除掉沒(méi)有與遠(yuǎn)程分支對(duì)應(yīng)的本地分支: git fetch -p 重命名遠(yuǎn)程分支在git中重命名遠(yuǎn)程分支,其實(shí)就是先刪除遠(yuǎn)程分支,然后重命名本地分支,再重新提交一個(gè)遠(yuǎn)程分支。 例如下面的例子中,我需要把 devel 分支重命名為 develop 分支: $ git branch -av * devel 752bb84 Merge pull request #158 from Gwill/devel master 53b27b8 Merge pull request #138 from tdlrobin/master zrong 2ae98d8 modify CCFileUtils, export getFileData remotes/origin/HEAD -> origin/master remotes/origin/add_build_script d4a8c4f Merge branch 'master' into add_build_script remotes/origin/devel 752bb84 Merge pull request #158 from Gwill/devel remotes/origin/devel_qt51 62208f1 update .gitignore remotes/origin/master 53b27b8 Merge pull request #138 from tdlrobin/master remotes/origin/zrong 2ae98d8 modify CCFileUtils, export getFileData 刪除遠(yuǎn)程分支: $ git push --delete origin devel To git@github.com:zrong/quick-cocos2d-x.git - [deleted] devel 重命名本地分支: git branch -m devel develop 推送本地分支: $ git push origin develop Counting objects: 92, done. Delta compression using up to 4 threads. Compressing objects: 100% (48/48), done. Writing objects: 100% (58/58), 1.38 MiB, done. Total 58 (delta 34), reused 12 (delta 5) To git@github.com:zrong/quick-cocos2d-x.git * [new branch] develop -> develop 然而,在 github 上操作的時(shí)候,我在刪除遠(yuǎn)程分支時(shí)碰到這個(gè)錯(cuò)誤: $ git push --delete origin devel remote: error: refusing to delete the current branch: refs/heads/devel To git@github.com:zrong/quick-cocos2d-x.git ! [remote rejected] devel (deletion of the current branch prohibited) error: failed to push some refs to 'git@github.com:zrong/quick-cocos2d-x.git' 這是由于在 github 中,devel 是項(xiàng)目的默認(rèn)分支。要解決此問(wèn)題,這樣操作:
把本地tag推送到遠(yuǎn)程git push --tags 獲取遠(yuǎn)程taggit fetch origin tag <tagname> 參考文章
|
|