How to list all unmerged changes in Git?

GitBranch

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

To list branches with commits not merged into master:

git branch --no-merged master

To list the relevant commits:

git cherry -v master <branch>

Solution 2 - Git

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.

Solution 3 - Git

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.

Solution 4 - Git

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 }

Solution 5 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlprsdView Question on Stackoverflow
Solution 1 - GitgawiView Answer on Stackoverflow
Solution 2 - GitMattView Answer on Stackoverflow
Solution 3 - GitjoanisView Answer on Stackoverflow
Solution 4 - Gitpavol.kutajView Answer on Stackoverflow
Solution 5 - GittamasdView Answer on Stackoverflow