GIT Cherry–Picking Commits Out Of Order

331 views Asked by At

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?

1

There are 1 answers

4
matt On

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.