🔀 Git: Fix a Cherry-Pick Dropping a Rename Across Two Branches
git cherry-pick replays a commit’s diff against the current branch using a three-way merge against that commit’s parent. If a file was renamed on the target branch after the two branches diverged, Git’s rename detection during the cherry-pick’s internal merge can fail to connect the two histories of the same logical file — the change either applies to a stale copy of the old filename, gets silently skipped as unrelated content, or produces a conflict that looks like a file was deleted.
🔎 The Problem
main: utils/format.js (renamed to utils/formatting.js, then edited) feature: a commit edits utils/format.js (old path, written before the rename) git cherry-pick <feature-commit> onto main -> CONFLICT (modify/delete): utils/format.js deleted in HEAD and modified in <feature-commit>. (actually a rename Git's three-way merge didn't connect)
✅ Fix: Confirm the Rename Relationship Before Resolving
- Before cherry-picking a commit from a branch where a file might have been renamed on either side, check
git log --follow --oneline -- <path>on both branches to confirm whether the file still exists under that name. - If a conflict presents as a delete/modify on a file you suspect was renamed, use
git statusandgit diff --find-renamesto confirm whether Git actually detected the rename before resolving — a naive “keep mine” or “keep theirs” at that point can silently discard the cherry-picked change entirely. - For a batch of commits spanning a rename, consider rebasing the whole range instead of cherry-picking commit by commit, since rebase’s merge machinery tracks renames across the full range rather than evaluating each commit against its single immediate parent in isolation.
🚨 Why This Is Dangerous
- A cherry-pick that reports success while actually dropping the renamed file’s change leaves no error to notice — the commit appears in the log, but the fix or feature it was supposed to carry over simply isn’t present in the resulting code.
A cherry-pick’s merge only connects two sides of a rename if it can actually recognize them as the same file — and a diff computed against an old path doesn’t automatically know the new one exists.

