Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find all commits that are in one branch but not in another using git?

Tags:

git

I've two branches, master and live. Master is the development branch and contains commits that aren't ready to go into live.

  • If a change is made in the master branch that needs to go into the live branch then they're cherry picked from master to live.
  • Sometimes commits are made to the live branch that are then either cherry picked into master or merged into master.

What I want to be able to do is view all the commits that are in master than aren't in live, I've had a good search on here and Google and I was using this:

git log --cherry-pick --no-merges --oneline master...live 

This worked until I merged live into master. But now it lists several commits that are in both.

So what is the correct command to view all commits that are in the master branch and not in the live branch?

like image 889
Rwky Avatar asked Dec 13 '12 10:12

Rwky


People also ask

How can I see all commits in one branch?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

How do I compare commits in two branches?

Compare commits between two branches In some cases, you may be interested in knowing the commit differences between two branches. In order to see the commit differences between two branches, use the “git log” command and specify the branches that you want to compare.

How do I see commits in master branch?

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.


2 Answers

You are very close. The correct command is:

git log --cherry-pick --oneline --no-merges --left-only master...live 

from the log manpage:

--left-only, --right-only

List only commits on the respective side of a symmetric range, i.e. only those which would be marked < resp. > by --left-right.

For example, --cherry-pick --right-only A...B omits those commits from B which are in A or are patch-equivalent to a commit in A. In other words, this lists the + commits from git cherry A B. More precisely, --cherry-pick --right-only --no-merges gives the exact list.

like image 146
Chronial Avatar answered Sep 28 '22 04:09

Chronial


git log master ^live --no-merges

like image 43
Kevin Bowersox Avatar answered Sep 28 '22 05:09

Kevin Bowersox