0

i have say two branch 'master' and 'current'. usually i make some changes in master and then cherrypick in curent. but sometimes i made some commit directly in current branch and forgot to cherry pick into master. now i want to get the list of all the commit id(hash) which are present in current branch but missing from master by any two way

  1. either they haven't been cherry picked in master
  2. or current branch wasn't merged in master.

how to get the list of these missing commits from master but in current branch?

Madhav Mishra
  • 11
  • 1
  • 5
  • " as far i know git cherry option is there?" - why aren't you mentioning this in your question then? It seems like you already know the answer. – Andrew C Oct 28 '14 at 00:10

2 Answers2

0

You shouldn't make a change in one and cherry pick it. Cherry picking is an exceptional case that should be done only rarely. I'm not sure I understand your workflow but what you should do is to make your changes into master and then merge it into (or rebase depending on how you want the tree) current. Cherry picking will apply the introduced diff as a new commit and so you cannot do any tracking. The following approach will work if you do merging (not cherry-picking).

git log master..current will give you commits that are reachable from current (i.e. in current) but will exclude ones that are reachable from master (i.e. which are in master). In other words, it will show you the commits that are in current which are not there in master.

Here is an example.

 /---B(current)
A 
 \---C(master)

Now, git log master..current will give you B. git log master..current will give you C.

All this will work only if you use merges properly. Cherry-picking breaks all this.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • what if i have to go with my existing workflow. i.e i have to get the commits in current branch which hasn't been cherrypicked in master. is there any way? as far i know git cherry option is there? – Madhav Mishra Oct 27 '14 at 06:52
  • Nope. Cherry picking bypasses the DAG completely. It's as if you manually patched the files and committed again. Git can't track the history for you. Why do you want to do this? It's just a matter of time before you hurt yourself. Read [this](http://stackoverflow.com/questions/1241720/git-cherry-pick-vs-merge-workflow) for some context. – Noufal Ibrahim Oct 27 '14 at 08:11
0

This is a duplicate but search is failing to find the original for me.

You can use either

git cherry

or

git log --cherry

(or --cherry-mark or --cherry-pick).

Note that listing SHAs is 100% reliable. Any of the cherry commands are usually pretty good, but can have false negatives.

Andrew C
  • 13,845
  • 6
  • 50
  • 57