开发者

How to list all unmerged changes in Git?

开发者 https://www.devze.com 2023-01-13 12:32 出处:网络
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.

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 mast开发者_运维百科er. Is there a way to do that?


To list branches with commits not merged into master:

git branch --no-merged master

To list the relevant commits:

git cherry -v master <branch>


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.


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.


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 }


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

0

精彩评论

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