判断分支是否需要merge的方法

git --help branch

NAME
       git-branch - List, create, or delete branches

SYNOPSIS
       git branch [--color[=<when>] | --no-color] [-r | -a]
               [--list] [-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>] [<pattern>...]
       git branch [--track | --no-track] [-l] [-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>]
(其他信息大家可以 命令行运行查看,此处不再列出)           

可以判断的命令参数:

--contains [<commit>]
    Only list branches which contain the specified commit (HEAD if not specified). Implies --list.

--no-contains [<commit>]
    Only list branches which don’t contain the specified commit (HEAD if not specified). Implies --list.

--merged [<commit>]
    Only list branches whose tips are reachable from the specified commit (HEAD if not specified). Implies --list, incompatible with --no-merged.

--no-merged [<commit>]
    Only list branches whose tips are not reachable from the specified commit (HEAD if not specified). Implies --list, incompatible with --merged.

提醒:

NOTES
       If you are creating a branch that you want to checkout immediately, it is easier to use the git checkout command with its -b option to create a branch and check it out with
       a single command.

       The options --contains, --no-contains, --merged and --no-merged serve four related but different purposes:

       ·   --contains <commit> is used to find all branches which will need special attention if <commit> were to be rebased or amended, since those branches contain the specified
           <commit>.

       ·   --no-contains <commit> is the inverse of that, i.e. branches that don’t contain the specified <commit>.

       ·   --merged is used to find all branches which can be safely deleted, since those branches are fully contained by HEAD.

       ·   --no-merged is used to find branches which are candidates for merging into HEAD, since those branches are not fully contained by HEAD.

故而可以利用如上的命令来看看需不需要merge

git branch --contains origin/master
git branch --merged origin/master
发布了236 篇原创文章 · 获赞 145 · 访问量 44万+

猜你喜欢

转载自blog.csdn.net/u011944141/article/details/103119972