154

Creating a branch for various topics, and not regularly deleting them when I don't need them any more, I have now ended up with about 50 branches.

I tried deleting branches but some of them have unmerged changes.

What I want is the ability to see exactly what changes are there in any branch on my repo that are not in master. Is there a way to do that?

Rafael Tavares
  • 3,489
  • 4
  • 25
  • 44
lprsd
  • 80,809
  • 47
  • 132
  • 167

5 Answers5

275

To list branches with commits not merged into master:

git branch --no-merged master

To list the relevant commits:

git cherry -v master <branch>
gawi
  • 13,540
  • 7
  • 40
  • 78
37

I came across this question when I was trying to remember the syntax of...

git log <branch> --not master --stat

This will show commits to <branch> that have not been merged to master. The --stat will include the files that were changed with the commits. You can also use this to compare any two branches by replacing master with a different branch name.

Matt
  • 371
  • 3
  • 3
4

This question is already well answered, but there is one more answer I think is worth documenting:

List all commits on any branch not already merged with master:

git log --all --not master

or, equivalently:

git log --all ^master

The --all picks up all branches, so you don't have to list them, then --not master or ^master removes master from the selection.

joanis
  • 6,977
  • 11
  • 26
  • 33
  • 1
    + some formatting for a more elegant output `git log --all --not master --graph --pretty=format:"%C(auto)%h%d%Creset %C(cyan)(%ci)%Creset %C(green)%cn %Creset %s" --name-status --date=short` – pavol.kutaj Jul 24 '21 at 04:27
0

For the PowerShell folk a little combination of what has been said above. If needed, replace master with main. Test by pasting into your shell.

$notMergedList = (git branch --no-merged master) -replace " ", ""
ForEach($branchItem in $notMergedList) {
  write-host "~~> branch: $branchItem" -Foregroundcolor DarkCyan
  git cherry -v master $branchItem }
pavol.kutaj
  • 311
  • 2
  • 10
-5

It is quite easy to get an overview of your branches with gitk.

tamasd
  • 5,526
  • 3
  • 26
  • 31