Guillaume Morin
Guillaume Morin

Reputation: 4010

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

Upvotes: 24

Views: 4857

Answers (1)

Adam Dymitruk
Adam Dymitruk

Reputation: 129546

 comm -12 <(sort <(git branch --no-merged master)) <(sort <(git branch --merged integration))

Upvotes: 20

Related Questions