Video in progress
You cherry-picked a hotfix onto `main`, and then the whole release branch was merged. What happens in the history?
The same change shows up twice with two different hashes. Most of the time the merge goes through without trouble, because the diff is identical, but if those lines were changed in between, an unexpected conflict or even the return of old code is possible.
📖 Answer
Cherry-pick does not move a commit: it rewrites its diff as a new commit. The new commit's parent and time, and therefore its hash, are different. To Git these two commits are unrelated.
In the usual case the merge swallows this: both sides have the same change, and the three-way merge accepts "both did the same thing".
The problematic case:
release: A --- H (hotfix) --- R (a refactor that rewrote H differently)
main: A --- H' (cherry-pick) --- M (merge of release)
In that situation a conflict appears, or if it is resolved wrongly, the old version comes back.
This is what I do in practice:
git cherry-pick -xadds "(cherry picked from commit ...)" to the message, which makes tracking easier;git log --cherry-mark --oneline main...releasemarks commits present on both sides (equal by patch) with=, and--cherry-pickdrops them from the list, leaving only the ones that truly differ;- if possible I change the direction: the hotfix is made on the oldest supported branch and merged upward. Then no cherry-pick is needed at all.
Sign up to mark studied questions and save your progress.