开发者

How can I get list of branches emerging from any branch in git?

开发者 https://www.devze.com 2022-12-13 00:56 出处:网络
How can I get list of branches emerging from any branch in开发者_JS百科 git ? Also what is the difference between fetch and pull command in git ?git fetch

How can I get list of branches emerging from any branch in开发者_JS百科 git ?

Also what is the difference between fetch and pull command in git ?


git fetch
git checkout <branch of interest>
git log --children <commit>

will print a list of descendant commits for a given one which partially answers your question.

pull does fetch and attempts to merge

fetch does not merge


How can I get list of branches emerging from any branch in git ?

Depending on what you mean here by "emerging" (and assuming that you meant "given branch" not "any branch"), it would be either git branch --contains <branch>, or git branch --merged <branch>.

Fro git-branch manpage:

SYNOPSIS
git branch [--color | --no-color] [-r | -a]
      [-v [--abbrev=<length> | --no-abbrev]]
      [(--merged | --no-merged | --contains) [<commit>]]
DESCRIPTION

With --contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit). With --merged, only branches merged into the named commit (i.e. the branches whose tip commits are reachable from the named commit) will be listed. With --no-merged only branches not merged into the named commit will be listed. If the argument is missing it defaults to HEAD (i.e. the tip of the current branch).


Kind of a play off of @CB Bailey but simplified. I use the following command to show all branches containing a commit.

git branch -a --contains <commit>


The second question is easier. A fetch merely updates the remote racking branches of your current repository from a remote repository (usually the origin), a pull performs a fetch and then merges a remote branch into the currently checked out branch. The exact branches fetched and merged can depend on the config, but git tries to "do the right thing" and succeeds in most common setups.

The first question is a bit more tricky because new branches can be created at any point in any repository from any commit in any given branch's history. In many repositories, most 'normal' branches are all offshoots of each other in some way.

What you can do is look at all branches git branch, git branch -a or git show-ref --heads for a more scriptable version, and see how the branches relate with a symmertic difference.

git log --oneline --left-right branch-a...branch-b

This will show the commits that are not common between the two branches, prefixing them with a < or > to show which branch they are on.

0

精彩评论

暂无评论...
验证码 换一张
取 消