如何找到已经从master中删除的本地git分支 [英] How to find local git branches that have been deleted from master
问题描述
在我们的工作流程中,开发分支机构已准备就绪,可以将它们推送到远程跟踪存储库,并将它们合并到主数据库中。当测试通过时,分支会被删除。
我一直在删除这些开发分支的本地版本,所以现在我有很多本地分支没有
是否有快速的方法可以找到我的仓库中的哪些分支已经从远程仓库中删除?
在refs / head下查找和删除本地分支
假设原始海报意味着他想在 refs / remotes / origin
下删除 refs / heads
下的本地分行,而不是远程追踪分行,然后找到分行已经被合并到 origin / master
中,只需使用以下内容:
#获取最新的原始副本/ master
$ git获取原点
#查找合并分支
$ git branch --merged origin / master
输出将显示已合并的分支nto origin / master
,因此可以安全地使用 git分支进行删除-d< branch>
。从用于 git分支的官方Linux Kernel Git文档 code>
:
- merged用于查找所有可以安全删除的分支,因为
在refs / remotes / origin
中删除远程追踪分支另一方面,如果原始海报意味着他想删除他的远程追踪分支,那么只需传递 -p
或 - prune
标记为 git fetch
:
$ git fetch -p origin
从官方Linux Kernel Git文档 git fetch
:
提取后,删除远程不再存在的任何远程追踪分支。
In our workflow, development branches which are production-ready get pushed to the remote tracking repository where they are merged into master. The branch is deleted when the tests pass.
I have been bad about deleting my local version of those development branches, so now I have many local branches which don't have a corresponding branch on origin.
Is there a quick way to find which branches in my repository have already been deleted from the remote repository?
Finding and deleting local branches under refs/heads
Assuming that the original poster means he wants to delete local branches under refs/heads
and not remote-tracking branches under refs/remotes/origin
, then to find branches that have already been merged into origin/master
, simply use the following:
# Fetch latest copy of origin/master
$ git fetch origin
# Find merged branches
$ git branch --merged origin/master
The output will show you branches which have been merged nto origin/master
, and are thus safe to delete with git branch -d <branch>
. From the official Linux Kernel Git documentation for git branch
:
"--merged" is used to find all branches which can be safely deleted, since those branches are fully contained by HEAD.
Deleting remote-tracking branches under refs/remotes/origin
If, on the other hand, the original poster meant that he wanted to delete his remote-tracking branches, then simply pass the -p
or --prune
flags to git fetch
:
$ git fetch -p origin
From the official Linux Kernel Git documentation for git fetch
:
After fetching, remove any remote-tracking branches which no longer exist on the remote.
这篇关于如何找到已经从master中删除的本地git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!