2

Simple Scenario: I have few commits on git branch A which was forked from master some time back. I would like to find out all pending commits that need to be merged back to master. Following command gives me list of these commits. $git log --cherry --oneline master..A

Now, in bit more complex scenario, I have another branch B which was also forked from master and has few commits that I would now like to integrate back to the master. However, couple of my developers have already cherry picked some of these commits onto their "private" branches (say, b1,b2,b3 - all forked from Branch B) and then, they have also cherry picked these commits from their private branches to the master (with new commit-hashes, that are different from original commit hashes on the 'B' branch). So, ideally, these need not be re-merged onto the master because they already have been merged on the master (just via different route of cherry-picks).

My question is: Is there any git command that can tell me what commits from B are still pending to be merged? I really DO NOT want to see commits that have been merged to master via some other (i.e., private, b1,b2,b3) branches. I am assuming that git is smart to know that the commit despite not being directly merged, may have been merged as part of cherry picking via other multiple branches.

In this graphical scenario, I'd like git command to show me that 3 commits (c7,c8 and c9) are still pending to be merged to master. Git Merge Scenario

2 Answers 2

4

git cherry master B-branch

It lists all the commits that are on B-branch but not on master with a leading + mark each line. If the line starts with a - mark, the following commit (of B-branch) has an equivalent commit on master (via rebase or cherry-pick), which can be ignored.

4
  • Hi ElpieKay, What is the definition of 'equivalent' commit? Is the file-content is compared for each participating commit? In my scenario, the merge process may have introduced minor 'extra' changes in commit#c5 when it was merged from branch-B to branch b1 - would it still cause it to show up with "+" - meaning 'pending merge' to master ? Jun 13, 2017 at 6:54
  • Hi @ElpieKay, I think I found answer to my comment on this post - so it appears that if the content did change during the merge process (with java projects, it is often the case when IDE tries to auto-correct imports prior to checkin) then it will be flagged as a pending commit. Please correct me if I am understanding it wrong. Jun 13, 2017 at 7:01
  • @UmeshAdtani if Commit A is cherry-picked to another branch as Commit A', then A and A' are equivalent commits.
    – ElpieKay
    Jun 13, 2017 at 7:49
  • my observation is that if the cherry-pick is straight-forward and no merge-conflicts or other changes were made, then it is being treated as equivalent, however, if any other changes got injected by the cherry-picking process, i.e., merge-conflict-resolutions, etc, then it is still being treated as not-equivalent, so it ends up showing "+ " prefix to the commit. The root-cause of this behaviour may be that the expected patch-id on the 'cherry-picked' commit on the target branch different from the original commit from where the changes were cherry-picked from. Jun 13, 2017 at 9:29
1

If you want to see the differences between the branches, I suggest that you see this command that you show it in a friendly way.

git log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
1
  • Seems this is equivalent to gitk branch1 branch2, isn't it? Oct 31, 2017 at 3:26

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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