<p>What is the best way to get a log of commits on a branch since the time it was branched from the current branch? My solution so far is:</p>

<pre><code>git log $(git merge-base HEAD branch)..branch
</code></pre>

<p>The documentation for <a href="http://git-scm.com/docs/git-diff" rel="noreferrer">git-diff</a> indicates that <code>git diff A...B</code> is equivalent to <code>git diff $(git-merge-base A B) B</code>. On the other hand, the documentation for <a href="http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html" rel="noreferrer">git-rev-parse</a> indicates that <code>r1...r2</code> is defined as <code>r1 r2 --not $(git merge-base --all r1 r2)</code>.</p>

<p>Why are these different? Note that <code>git diff HEAD...branch</code> gives me the diffs I want, but the corresponding git log command gives me more than what I want.</p>

<p>In pictures, suppose this:</p>

<pre>
         x---y---z---branch
        /
---a---b---c---d---e---HEAD
</pre>

<p>I would like to get a log containing commits x, y, z.</p>

<ul>
<li><code>git diff HEAD...branch</code> gives these commits</li>
<li>however, <code>git log HEAD...branch</code> gives x, y, z, c, d, e.</li>
</ul>

[{'answer_id': 53573, 'author': 'Lily Ballard', 'author_id': 582, 'author_profile': 'https://Stackoverflow.com/users/582', 'pm_score': 9, 'selected': True, 'text': '<p>In the context of a revision list, <code>A...B</code> is how <code>git-rev-parse</code> defines it. git-log takes a revision list. <code>git-diff</code> does not take a list of revisions - it takes one or two revisions, and has defined the <code>A...B</code> syntax to mean how it\'s defined in the <code>git-diff</code> manpage. If <code>git-diff</code> did not explicitly define <code>A...B</code>, then that syntax would be invalid. Note that the <code>git-rev-parse</code> manpage describes <code>A...B</code> in the "Specifying Ranges" section, and everything in that section is only valid in situations where a revision range is valid (i.e. when a revision list is desired).</p>\n\n<p>To get a log containing just x, y, and z, try <code>git log HEAD..branch</code> (two dots, not three). This is identical to <code>git log branch --not HEAD</code>, and means all commits on branch that aren\'t on HEAD.</p>\n'}, {'answer_id': 273683, 'author': 'skiphoppy', 'author_id': 18103, 'author_profile': 'https://Stackoverflow.com/users/18103', 'pm_score': 6, 'selected': False, 'text': "<pre><code>git cherry branch [newbranch]\n</code></pre>\n\n<p>does exactly what you are asking, when you are in the <code>master</code> branch.</p>\n\n<p>I am also very fond of:</p>\n\n<pre><code>git diff --name-status branch [newbranch]\n</code></pre>\n\n<p>Which isn't exactly what you're asking, but is still very useful in the same context.</p>\n"}, {'answer_id': 2831173, 'author': 'Clintm', 'author_id': 3384609, 'author_profile': 'https://Stackoverflow.com/users/3384609', 'pm_score': 5, 'selected': False, 'text': '<p>This is similar to the answer I posted on: <a href="https://stackoverflow.com/questions/2176278/preview-a-git-push/2831135#2831135">Preview a Git push</a></p>\n\n<p>Drop these functions into your Bash profile:</p>\n\n<ul>\n<li>gbout - git branch outgoing</li>\n<li>gbin  - git branch incoming</li>\n</ul>\n\n<p>You can use this like:</p>\n\n<ul>\n<li>If on master: gbin branch1  &lt;-- this\nwill show you what\'s in branch1 and\nnot in master</li>\n<li>If on master: gbout\nbranch1 &lt;-- this will show you what\'s\nin master that\'s not in branch 1</li>\n</ul>\n\n<p>This will work with any branch.</p>\n\n<pre><code>function parse_git_branch {\n  git branch --no-color 2&gt; /dev/null | sed -e \'/^[^*]/d\' -e \'s/* \\(.*\\)/\\1/\'\n}\n\nfunction gbin {\n    echo branch \\($1\\) has these commits and \\($(parse_git_branch)\\) does not\n    git log ..$1 --no-merges --format=\'%h | Author:%an | Date:%ad | %s\' --date=local\n}\n\nfunction gbout {\n    echo branch \\($(parse_git_branch)\\) has these commits and \\($1\\) does not\n    git log $1.. --no-merges --format=\'%h | Author:%an | Date:%ad | %s\' --date=local\n}\n</code></pre>\n'}, {'answer_id': 11689964, 'author': 'nopsoft', 'author_id': 1557959, 'author_profile': 'https://Stackoverflow.com/users/1557959', 'pm_score': 2, 'selected': False, 'text': "<pre><code>git log --cherry-mark --oneline from_branch...to_branch\n</code></pre>\n\n<p>(3dots) but sometimes it shows '+' instead of '='</p>\n"}, {'answer_id': 13465814, 'author': 'Debajit', 'author_id': 2288585, 'author_profile': 'https://Stackoverflow.com/users/2288585', 'pm_score': 5, 'selected': False, 'text': '<p>What you want to see is the list of outgoing commits. You can do this using</p>\n\n<pre><code>git log master..branchName \n</code></pre>\n\n<p>or </p>\n\n<pre><code>git log master..branchName --oneline\n</code></pre>\n\n<p>Where I assume that "branchName" was created as a tracking branch of "master".</p>\n\n<p>Similarly, to see the incoming changes you can use:</p>\n\n<pre><code>git log branchName..master\n</code></pre>\n'}, {'answer_id': 18241536, 'author': 'Alex V', 'author_id': 327934, 'author_profile': 'https://Stackoverflow.com/users/327934', 'pm_score': 3, 'selected': False, 'text': '<p>Throw a -p in there to see some FILE CHANGES</p>\n\n<pre><code>git log -p master..branch\n</code></pre>\n\n<p>Make some aliases:</p>\n\n<pre><code>alias gbc="git branch --no-color | sed -e \'/^[^\\*]/d\' -e \'s/* \\\\(.*\\\\)/\\1/\'"\n\nalias gbl=\'git log -p master..\\`gbc\\`\'\n</code></pre>\n\n<p>See a branch\'s unique commits:</p>\n\n<pre><code>gbl\n</code></pre>\n'}, {'answer_id': 19315225, 'author': 'Dominik Ehrenberg', 'author_id': 2410151, 'author_profile': 'https://Stackoverflow.com/users/2410151', 'pm_score': 2, 'selected': False, 'text': "<p>I found</p>\n\n<pre><code>git diff &lt;branch_with_changes&gt; &lt;branch_to_compare_to&gt;\n</code></pre>\n\n<p>more useful, since you don't only get the commit messages but the whole diff. If you are already on the branch you want to see the changes of and (for instance) want to see what has changed to the master, you can use:</p>\n\n<pre><code>git diff HEAD master\n</code></pre>\n"}, {'answer_id': 33091430, 'author': 'NDavis', 'author_id': 1457295, 'author_profile': 'https://Stackoverflow.com/users/1457295', 'pm_score': 3, 'selected': False, 'text': '<p>To see the log of the current branch since branching off master:</p>\n\n<p><code>git log master...</code></p>\n\n<p>If you are currently on master, to see the log of a different branch since it branched off master:</p>\n\n<p><code>git log ...other-branch</code></p>\n'}, {'answer_id': 37115352, 'author': 'Michael Durrant', 'author_id': 631619, 'author_profile': 'https://Stackoverflow.com/users/631619', 'pm_score': 4, 'selected': False, 'text': "<p>When already in the branch in question use</p>\n<pre><code>git diff master...\n</code></pre>\n<p>Which combines several features:</p>\n<ul>\n<li>it's super short</li>\n<li>shows the actual changes</li>\n<li>Allow for master having moved forward</li>\n</ul>\n"}, {'answer_id': 65117801, 'author': 'Denton L', 'author_id': 4762298, 'author_profile': 'https://Stackoverflow.com/users/4762298', 'pm_score': 0, 'selected': False, 'text': '<p>With Git 2.30 (Q1 2021), &quot;git diff A...B(man)&quot; learned &quot;git diff --merge-base A B(man), which is a longer short-hand to say the same thing.</p>\n<p>Thus you can do this using <code>git diff --merge-base &lt;branch&gt; HEAD</code>. This should be equivalent to <code>git diff &lt;branch&gt;...HEAD</code> but without the confusion of having to use range-notation in a diff.</p>\n'}]
['https://Stackoverflow.com/questions/53569', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/893/']