Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git list branches merged into a branch but not into another

Here is a example graph of branch/commit history:

A---  master
|\
| B-----G--------P feature2
|\       \        \
| -----F--J--L--O--Q integration
|\    /     /  /
| C--E--H--K  /    feature1
 \           /
  D---------M feature3

In a normal circumstances, we merge integration branch into master and done. But... there are exceptional cases where only some specific feature must be merged into master... ex: only feature1. In that case, feature1 branch is merged into master (commit R):

A-------------------------R   master
|\                       /
| B-----G--------P      /     feature2
|\       \        \    /
| -----F--J--L--O--Q  /       integration
|\    /     /  /     /
| C--E--H--K--/------         feature1
 \           /
  D---------M                 feature3

Question: I would like a command that would tell me which branches are merged in integration but not in master. Result should be: feature2 and feature3.

Is a cross-reference between these 2 commands the only way ?

git branch --no-merged master
git branch --merged integration

Or, it could be also a command that list merge commits in integration branch not present in master. Result should be: J,O,Q

like image 513
Guillaume Morin Avatar asked Nov 09 '11 20:11

Guillaume Morin


People also ask

How do you check if a branch is already merged with any branch or not?

You can use the git merge-base command to find the latest common commit between the two branches. If that commit is the same as your branch head, then the branch has been completely merged.

How do you check the list of those branches you haven't yet merged into the main branch of the repository?

4 Answers. Show activity on this post. then it will show you branches which have been merged into the current HEAD (so if you're on master , it's equivalent to the first command; if you're on foo , it's equivalent to git branch --merged foo ).

How can you tell if two branches are merged?

Suppose you are on branch master and you want to check if the git merge origin/devel will work. Then just do: git merge-tree `git merge-base origin/devel master` master origin/devel .

What happens to branches after merging?

When you perform a merge, you effectively merge one branch into another—typically a feature branch or bug fix branch into a main branch such as master or develop. Not only will the code changes get merged in, but also all the commits that went into the feature branch.


1 Answers

 comm -12 <(sort <(git branch --no-merged master)) <(sort <(git branch --merged integration)) 
like image 147
Adam Dymitruk Avatar answered Sep 21 '22 15:09

Adam Dymitruk