Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 822115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:45:09+00:00 2026-05-15T02:45:09+00:00

If I cherry-pick from multiple branches, is there a simple way to figure out

  • 0

If I cherry-pick from multiple branches, is there a simple way to figure out where the commit was coming from (e.g. the sha of the original commit)?

Example:
– at master branch
– cherry pick commit A from a dev branch
– A becomes D at the master branch

Before:

* B (master) Feature Y
| * C (dev) Feature Z
| * A Feature X
|/
* 3
* 2
* 1  

After:

* D (master) Feature X
* B Feature Y
| * C (dev) Feature Z
| * A Feature X
|/
* 3
* 2
* 1  

Is it possible to figure out that D was cherry-picked from A (aside from searching for the commit message)?

Edit:
Although I will go with daggy-fixes (see VonCs answer) I accepted Chris Johnsens answer because it is closer to the actual question. Thanks guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:45:09+00:00Added an answer on May 15, 2026 at 2:45 am

    By default, the information about the original, “cherry” commit is not recorded as part of the new commit.

    Record the Source Commit in the Commit Message

    If you can force the use of particular workflows/options,
    git cherry-pick has the -x option:

    When recording the commit, append to the original commit message a note that indicates which commit this change was cherry-picked from.

    This is obviously useless if you can not rely on the cherry pickers using the option.
    Also, since the recorded information is just plain text—not an actual reference as far as Git is concerned—even if you use -x, you still have to take steps to make sure that the original commit is kept alive (e.g. is is part of the DAG of a tag or a non-rewinding branch).

    git cherry and git patch-id

    If you can restrict your search to two particular branches of the history DAG, then git cherry can find both “unpicked” and “picked” cherries.

    Note: This command (and the related git patch-id) can only identify conflict-free cherries that were individually picked without extra changes. If there was a conflict while picking the cherry (e.g. you had to slightly modify it to get it to apply), or you used -n/--no-commit to stage extra changes (e.g. multiple cherries in a single commit), or the content of the commit was rewritten after the picking, then you will have to rely on commit message comparison (or the -x information if it was recorded).

    git cherry is not really designed to identify the origin of picked cherries, but we can abuse it a bit to identify single cherry pairs.

    Given the following history DAG (as in the original poster’s example):

    1---2---3---B---D  master
             \
              A---C    dev
    # D is a cherry-picked version of C
    

    you will see something like this:

    % git cherry master dev
    + A
    - C
    % git cherry dev master
    + B
    - D
    

    (A, B, C, and D are full SHA-1 hashes in the real output)

    Since we see one cherry (the - lines) in each list, they must form a cherry pair. D was a cherry picked from C (or vice versa; you can not tell by the DAG alone, though the commit dates might help).

    If you are dealing with more than one potential cherry, you will have to “roll your own” program to do the mapping. The code should be easy in any language with associative arrays, hashes, dictionaries, or equivalent. In awk, it might look like this:

    match_cherries() {
        a="$(git rev-parse --verify "$1")" &&
        b="$(git rev-parse --verify "$2")" &&
        git rev-list "$a...$b" | xargs git show | git patch-id |
        awk '
            { p[$1] = p[$1] " " $2 }
        END { 
                for (i in p) {
                    l=length(p[i])
                    if (l>41) print substr(p[i],2,l-1)
                }
            }'
    }
    match_cherries master dev
    

    With an extended example that has two picked cherries:

    1---2---3---B---D---E  master
             \
              A---C        dev
    # D is a cherry-picked version of C
    # E is a cherry-picked version of A
    

    The output might look like this:

    match_cherries master dev
    D C
    E A
    

    (A, C, D, and E are full SHA-1 hashes in the real output)

    This tells us that C and D represent the same change and that E and A represent the same change. As before, there is no way to tell which of each pair was “the first” unless you also consider (e.g.) the commit dates of each commit.

    Commit Message Comparison

    If your cherries were not picked with -x, or they are “dirty” (had conflicts, or other changes added to them (i.e. with --no-commit plus staging extra changes, or with git commit --amend or other “history rewriting” mechanism)), then you may have to fall back on less the less reliable technique of comparing commit messages.

    This technique works best if you can find some bit of the commit message that is likely to be unique to the commit and is unlikely to have changed in the commit that resulted from the cherry pick. The bit that would work best would depend on the style of commit messages used in your project.

    Once you have picked out an “identifying part” of the message, you can use git log to find commits (also demonstrated in Jefromi’s answer).

    git log --grep='unique part of the commit message' dev...master
    

    The argument to --grep is actually a regular expression, so you might need to escape any regexp metacharacters ([]*?.\).

    If you are not sure which branches might hold the original commit and the new commit, you can use --all as Jefromi showed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've done a manual cherry pick of a commit from one project into my
I want to cherry pick from one branch to another, but they diverged strongly.
Given that two branches have diverged and a specific commit from one branch (and
I'm currently trying to cherry-pick a feature from the trunk of an OSS project
I tried to use git cherry-pick for merging some commits from master and then
On reading the man page for git cherry-pick, my understanding is that it takes
For moving an individual from one branch to another I realize that there are
I'm working with a git repository that needs a commit from another git repository
We recently attempted a large, cherry picked merge. First we did a full merge
In Subversion, it is easy to merge a range of changesets/diffs from a branch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.