Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see which commits in one branch aren't in the other?

Tags:

git

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 commits in a specific file?

On Linux you can use gitk for this. It can be installed using "sudo apt-get install git-gui gitk". It can be used to see commits of a specific file by "gitk <Filename>".


The little-used command git cherry shows you the commits which haven't yet been cherry-picked. The documentation for git cherry is here, but, in short, you should just be able to do:

git checkout devel
git cherry next

... and see output a bit like this:

+ 492508acab7b454eee8b805f8ba906056eede0ff
- 5ceb5a9077ddb9e78b1e8f24bfc70e674c627949
+ b4459544c000f4d51d1ec23f279d9cdb19c1d32b
+ b6ce3b78e938644a293b2dd2a15b2fecb1b54cd9

The commits that begin with + will be the ones that you haven't yet cherry-picked into next. In this case, I'd only cherry-picked one commit so far. You might want to add the -v parameter to the git cherry command, so that it also outputs the subject line of each commit.


Also, you can use

git log --left-right --graph --cherry-pick --oneline devel...next

to get a nice list of actual different commits not shared between the branches.

The operative word is --cherry-pick

--cherry-pick

Omit any commit that introduces the same change as another commit on the "other side" when the set of commits are limited with symmetric difference. For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right, like the example above in the description of that option. It however shows the commits that were cherry-picked from the other branch (for example, "3rd on b" may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.

Update As mentioned in a comment, recent versions of git added --cherry-mark:

--cherry-mark

Like --cherry-pick (see below) but mark equivalent commits with = rather than omitting them, and inequivalent ones with +.


You might could try doing git log subsets:

git log --oneline devel ^next

How about

git log next..devel

Result is similar to Byran's answer (different order of commits) but both of our answers will produce commits that are different between the branches, rather just showing what's in one branch and not in the other.