Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Git, show all commits that are in one branch, but not the other(s)

I have an old branch, which I would like to delete. However, before doing so, I want to check that all commits made to this branch were at some point merged into some other branch. Thus, I'd like to see all commits made to my current branch which have not been applied to any other branch [or, if this is not possible without some scripting, how does one see all commits in one branch which have not been applied to another given branch?].

like image 708
sircolinton Avatar asked Nov 10 '09 20:11

sircolinton


People also ask

How can I see commits from one branch?

Git rev-list will list commits in one branch that are not in another branch. It is a great tool when you're trying to figure out if code has been merged into a branch or not. Using the --oneline option will display the title of each commit.

How do I see the commit differences between branches in git?

In order to see the commit differences between two branches, use the “git log” command and specify the branches that you want to compare. Note that this command won't show you the actual file differences between the two branches but only the commits.

How do I check my master commits?

To confirm, you can run git branch . The branch that you are on will be the one with a * next to it. Git checkout might fail with an error message, e.g. if it would overwrite modified files. Git branch should show you the current branch and git log master allows you to view commit logs without changing the branch.


1 Answers

To see a list of which commits are on one branch but not another, use git log:

git log --no-merges oldbranch ^newbranch 

...that is, show commit logs for all commits on oldbranch that are not on newbranch. You can list multiple branches to include and exclude, e.g.

git log  --no-merges oldbranch1 oldbranch2 ^newbranch1 ^newbranch2 

Note: on Windows command prompt (not Powershell) ^ is an escape key, so it needs to be escaped with another ^:

git log --no-merges oldbranch ^^newbranch 
like image 124
jimmyorr Avatar answered Nov 11 '22 14:11

jimmyorr