Safeguard
Developer Tools•

How do you record where a backported patch came from in a fork?

Use cherry-pick with the x option to stamp the source commit in the message, and add a note when a conflict stops Git from doing it. Keep the trail.

Safeguard Security Team
4 min read

Cherry-pick the upstream commit with the x option. Git appends a line naming the original commit to your commit message, so anyone can trace the backport. The line is added only when the pick has no conflicts, so for conflicted picks you must write the reference yourself.

Why the trail matters

A backported security fix is a promise: this code matches an upstream fix. Months later someone asks which advisory it answers and whether it still applies. Without a pointer to the source commit, the answer is archaeology. With one, it takes seconds.

The trail also helps the sync. When you later merge a newer upstream, a recorded source commit lets you see that the upstream version has replaced your backport, so you can drop your copy.

The command

git cherry-pick -x FIX_COMMIT

The Git documentation says the option appends a line reading "cherry picked from commit" followed by the original commit ID to the original commit message, to show where the change came from. It also states this is done only for cherry-picks without conflicts, and cautions against using the option when you are cherry-picking from your own private branch, since the hash is not useful to anyone else.

When there is a conflict

Backports to an older or modified base often conflict. After you resolve and commit, the source line is not added for you. Write it by hand in the message body:

Fix path traversal in archive extraction

Backport of upstream commit FULL_HASH
Advisory: ADVISORY_ID
Adapted: removed use of helper that does not exist in our base

The adapted line is the valuable part. It tells a future reviewer that the patch is not identical to upstream, so a patch equivalence check will not match it, and that a human should compare it with the upstream fix on the next sync.

A message template

LinePurpose
Summary under 70 charactersSearchable in the log
Backport of upstream commit, full hashLinks to the source
Advisory or issue IDLinks to the reason
Adapted: what you changed and whyFlags a non-identical patch
Remove when: conditionSays when the patch can go

Query your backports later

Because the messages follow a pattern, you can list every backport with a log search on the message text. Feed that list into your fork notes or tracker. See carrying a patch while waiting for an upstream merge for the full lifecycle, and whether your fork contains an upstream security fix for checking that a backport counts.

Review the list at every sync. Each entry should end in one of three ways: kept with a reason, replaced by the upstream version, or dropped because the code is gone.

Where Safeguard fits

Safeguard's fix PRs, which are off by default and need your approval per category, show the same habit in the open: a reviewable change that says what it fixes. You can check what your build contains with a free scan at gold.safeguard.sh/scan.

Try it yourself

Click through it at your own pace, or open it full screen. Notice how the fixed version and the finding it resolves are shown together.

Quick check

Does the x option always add the source line?

No. Git adds it only for cherry-picks without conflicts. After a conflict, write the reference in the message yourself.

Why add an adapted line?

It warns future reviewers that your patch differs from upstream, so they compare it by hand at the next sync.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.