スタック・オーバーフローに参加する
685万人以上のプログラマーが集まるスタック・オーバーフローに参加しませんか?
簡単な登録後、すぐにご利用いただけます。
登録

I have two branches devel and next. In devel I have a more or less huge amount of commits. Some of the commits are cherry picked in next. Also I added some commits to next which are merged to devel.

Now I would like to see what is missing in next, so I can test the changes in detail before bringing them to next. My question is now, how can I see which commits are in devel but not in next?

share|improve this question
    
Possibly related: Using Git, show all commits that are in one branch, but not the other(s). – user456814 May 28 '14 at 16:54
    
your title is a bit misleading, as what you want to compare is the tip of both branches. and I came here looking for a solution two compare specific (different) commits of two branches – thebugfinder Feb 10 '15 at 7:49
up vote 144 down vote accepted

The little-used command git cherry shows you the changes 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 being 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.

Update: I got the branches the wrong way round in my initial version of the example - I've fixed that now.

share|improve this answer
    
Great, this what I needed. It would also be nice to get a short description of the tests, but I can script this. – Sascha Effert Sep 28 '11 at 12:54
12  
You don't need to git checkout devel, you can just do git cherry next devel. – Robin Winslow Oct 21 '13 at 8:21
10  
“might want to add the -v? Cherry without a -v is like ls without an -la. ;-J – Slipp D. Thompson Sep 14 '14 at 20:23
    
And you wouldn't know of a way to get cherry to mark or exclude equivalent commits, would you? cherry seems like a plumbing command, but doesn't (appear to) offer many options. For what I'm currently in the middle of, git cherry gives me false positives, but @sehe's git log --cherry-pick correctly excludes the previously-picked/rebased commits. – Slipp D. Thompson Sep 14 '14 at 20:38
1  
this is now my new favourite command <3 – Christian Hagelid Jul 5 '16 at 0:20

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 +.

share|improve this answer
1  
This did not work for me. My version of git does not know --one-line, therefore I removed it. Then I had to exchange devel and next and it worked. Very nice! – Sascha Effert Sep 28 '11 at 13:35
    
@SaschaEffert: you did not have to switch devel and next (notice THREE dots, not TWO). That said, things may be different if you used an ancient version of git (?) but in that case you should have gotten a rev-parse error on the three dots. – sehe Sep 28 '11 at 13:39
2  
For fun, I worked out that the '...' (symmetrical difference) rev-parse syntax was added in July 2006, and the documentation for it was updated in June 2008. The joy of open source! – sehe Sep 28 '11 at 13:59
1  
'gls --first-parent --cherry-mark --left-only develop...next' where gls is my git log alias with all the pretty formatting. cherry-mark shows both cherry picked and not-cherry picked commits on develop, but marks them differently. – anjdreas Jun 24 '14 at 7:14
    
@AndreasLarsen Yeah, I use cherry-mark too these days. It was a recent addition. (Mentioned it in the answer) – sehe Jun 24 '14 at 7:29

You might could try doing git log subsets:

git log --oneline devel ^next
share|improve this answer
2  
this is so good! – Jamund Ferguson Sep 19 '13 at 22:44
2  
This is the best solution in my opinion (@sehe's answer also shows commits in next that are not in devel - in the OP's context, there are none, but in mine there are - using --left-only would have been better). However, this one can be improved a bit by adding --no-merges to omit any merge commits (e.g. if a feature or hotfix branch was merged (separately) into both devel and next). Strictly speaking, of course, conflict resolution in merges may create other differences, but that is usually not the case. The --no-merges option can usefully be applied to the other answers as well. – Alex Dupuy Jan 21 '14 at 0:32

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.

share|improve this answer
2  
You can also omit the second branch if you are currently on that branch. i.e. git log next.. – jmaxyz Sep 14 '15 at 17:16

To get the list of commits that were not integrated into the release branch (next) you may use:

git rev-list --reverse --pretty="TO_TEST %h (<%ae>) %s" --cherry-pick --right-only origin/release_branch...origin/development_branch | grep "^TO_TEST " > NotIntegratedYet.txt

Check git-rev-list for more info.

share|improve this answer
    
this answer's command is missing the actual branches in question, i.e. next...devel – Alex Dupuy Jan 21 '14 at 0:28
    
@AlexDupuy Yah, it's a pretty half-assed answer. Since it's also not the simplest answer and doesn't explain why this approach would be better, I'm -1-ing it. – Slipp D. Thompson Sep 14 '14 at 20:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.