Search code examples
gitgit-for-windows

Differences between git cherry and git log --cherry commands


git cherry develop feature/ABC - 1014d04c60efccb5d0b8762af1371831bb234b17

git cherry command correctly shows that the commit 1014d04 (marked with -) can be dropped from the feature branch during rebase against develop. Since it was already cherry-picked to develop.

However git log cherry commands do not seem to work (marked with +)

git log --cherry --oneline develop..feature/ABC + 1014d04 adding some comment

git log --cherry-mark --oneline develop..feature/ABC + 1014d04 adding some comment

I'm on

git --version git version 2.12.0.windows.1


Solution

  • The --cherry-mark and --cherry options effectively require that you take a symmetric difference. This is clearer from the description of --cherry:

    --cherry

      A synonym for --right-only --cherry-mark --no-merges; useful to limit the output to the commits on our side and mark those that have been applied to the other side of a forked history with git log --cherry upstream...mybranch, similar to git cherry upstream mybranch.

    Note the three dots here, which invoke the symmetric difference code. This takes commits that are on either branch, but not on both branches, i.e., it excludes their merge base(s) and any ancestor commits. Commits selected therefore must be reachable exclusively from the ID on the left—in this case, upstream—or the ID on the right (mybranch), but not both. The --left-right option would mark each commit as to which "leg" reaches it, while --right-only discards the selected left-side commits, but only after equivalent commits are marked.

    (It is possible to use --cherry-mark without --left-only or --right-only, but it's not that useful, I think: you cannot tell which side the commits come from. Mixing --cherry-mark with --left-right replaces the cherry marking with the left/right marking (!).)