git 刪除遠端已經(jīng)被刪除然而本地還存在的分支
1. 修剪不在遠程倉庫上的跟蹤分支
git remote prune origin
- 如果git倉庫將branch1被刪除,可以用用
git remote prune origin
刪除在本地電腦上的remotes/origin/branch1
-
git remote show origin
可以看到下面所示,這樣的可以通過git remote prune origin
刪除refs/remotes/origin/branch1 stale (use 'git remote prune' to remove)
-
- 上述只針對Deletes stale references associated with <name>. 分支(stale為三個月沒有提交的分支)
branch1 不會被刪除 branch2 remotes/origin/branch1 刪除這個 remotes/origin/branch2
2. 本地分支尚未刪除,要實現(xiàn)刪除本地分支
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d
詳解:
-
git branch -vv
該命令顯示本地所有分支關聯(lián)的遠程分支,本地存在但是遠端不存在的分支為gone
狀態(tài)。branch1 ec2d1b1a [origin/branch1: gone] feat: *** branch2 cdc6092d [origin/branch2: behind 45] feat: *** branch3 e51edba2 [origin/branch3] Merge branch 'branch3' into dev
-
grep 'origin/.*: gone]'
對于上述結果利用grep命令行語句查找gone
得到:branch1 ec2d1b1a [origin/branch1: gone] feat: ***
awk '{print $1}'
- 使用awk命令行語句分割上面結果
branch1
-
xargs git branch -d
上述過程得到遠端已經(jīng)刪除本地還沒刪除的分支名稱,在通過xargs將其作為參數(shù)傳給下一個命令git branch -d
Deleted branch branch1 (was ec2d1b1a).
參考
git remote prune origin does not delete the local branch even if its upstream remote branch is deleted文章來源地址http://www.zghlxwxcb.cn/news/detail-705967.html
文章來源:http://www.zghlxwxcb.cn/news/detail-705967.html
到了這里,關于在 Git 中刪除不再位于遠程倉庫中的本地分支的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!