Git:查找未合并到特定远程分支的远程分支

3
找到本地分支,这些分支没有合并到特定的本地分支(develop),可以通过以下步骤实现:
git branch --no-merged develop

但是我如何找到未合并到特定远程分支的远程分支呢?目的是在本地保留这些未合并的分支,同时将它们从远程删除。
2个回答

3

要列出远程分支,请使用-r标志,并使用适当的远程名称引用远程分支前缀:

git branch -r --no-merged origin/develop
           ^^             ^^^^^^^ 

藏在git分支帮助文档中的是对此的描述:
$ git branch --help
NAME
       git-branch - List, create, or delete branches

SYNOPSIS
       git branch [--color[=<when>] | --no-color] [--show-current]
               [-v [--abbrev=<length> | --no-abbrev]]
               [--column[=<options>] | --no-column] [--sort=<key>]
               [(--merged | --no-merged) [<commit>]]
               [--contains [<commit]] [--no-contains [<commit>]]
               [--points-at <object>] [--format=<format>]
               [(-r | --remotes) | (-a | --all)]                           # <----
               [--list] [<pattern>...]
       git branch [--track | --no-track] [-f] <branchname> [<start-point>]
       git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
       git branch --unset-upstream [<branchname>]
       git branch (-m | -M) [<oldbranch>] <newbranch>
       git branch (-c | -C) [<oldbranch>] <newbranch>
       git branch (-d | -D) [-r] <branchname>...
       git branch --edit-description [<branchname>]

DESCRIPTION
...
       -r, --remotes
           List or delete (if used with -d) the remote-tracking branches. 
           Combine with --list to match the optional pattern(s).
...


1
请注意,在执行此操作之前,您可能希望运行git fetchgit remote update命令,也许还可以加上--prune选项,以便更新本地Git对远程Git的分支名称和哈希ID的副本。 - undefined
@torek:谢谢!是的,在Windows上删除了origin分支后,我在macOS上登录后必须执行git fetch --prune命令。 - undefined

0
尝试使用-a标志来查看本地和远程分支: 尝试使用-r标志仅查看远程分支(根据@phd在评论中的建议)。
类似于这样:
git branch -a --no-merged origin/master

或者只查看远程分支:

git branch -r --no-merged origin/master

-r 是 OP 想要列出仅为 remote 而非合并的分支。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接