-1

I have 1 file

I modify code on one part of the file and do commit A

I modify code on another part of the file and do commit B

If I cherry–pick Commit B from source to release first, and then Commit A at a later late, will the changes from Commit B be deleted after Commit A overrides it, or will changes from Commit A be merged into the file with changes from Commit B and both changes will stay?

K. Ventura
  • 91
  • 2
  • 14

1 Answers1

1

A cherry pick is based on a diff from the parent. If you cherry pick B, Git will look at the difference between A and B (because A is B's parent) and that's all it will apply to release. If that difference is just "code on another part of the file", then that's all you'll get at that time.

Then later when you cherry pick A, Git will look at the difference between A and its parent, which is just the "code on one part of the file". And so that's all you'll get at that time. Nothing will be "deleted" or "overridden" — Git never behaves like that.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    Cherry pick uses merge logic. You might want to read my explanation of what a merge is: https://www.biteinteractive.com/understanding-git-merge/ – matt Dec 01 '22 at 16:56
  • or take a look at sequencer.c where all the gory details are laid out. – eftshift0 Dec 01 '22 at 17:05
  • Yes I see, but the parent is the unmodified file in the release branch, so during the first cherry–pick, commit B just adds a change to the file in the release, but then during the second cherry–pick, will the file from commit A copy and replace the file in the release, or will only the changes from commit A be added into the release's file? – K. Ventura Dec 01 '22 at 17:14
  • 1
    I have said what it does. It's a merge. – matt Dec 01 '22 at 17:25