Search code examples
git-mergegit-cherry-pick

How can I track git cherry-pick commits between branches


I have a long standing patch branch and a develop branch. I want to cherry-pick specific changes from develop to the patch branch.

When I do, I get new commits with no link to the old commit.

Is there a way to cherry pick and maintain the parental link to the branch for that commit?

is adding "-x" the best I can do?

Thanks


Solution

  • Yes, -x is really the only way to reference the commit that you cherry-picked.

    If you want to maintain the parent relationship of your commits, you would need to merge the branches. My guess would be that you would want to merge the patch branch with the develop branch so that you keep your work properly segregated.

    Though based on the way you phrased the question, I think that you might have a misconception about commits. They don't have a "link" to a branch. Rather each commit has a single parent commit that they point to. Merge commits have multiple parents to show which commits they are merging together. A branch is really just a pointer to a commit. A commit can exist on multiple branches either because it was merged or you created a new branch based from it or a later commit.

    What git cherry-pick does is make a copy of the changes that you made on one branch and apply them to a different location. You do this because you don't want the rest of the history coming along with this particular change. If you want to maintain a history, you would git merge or git rebase the changes from one branch to another.