Learning center

Tell the next engineer which fixes are already on the release branch

Use git cherry -v release main to list which commits from main have an equivalent on the release branch, and record the source with git cherry-pick -x. The output of git log release..main cannot answer the question, because a cherry-picked commit has a new ID.

Two lists that disagree#

In the fixture, main has "fix b" and "fix c". The release branch received "fix b" by cherry-pick.

$ git log --oneline rel..main
a1092a2 fix c
6eaa3da fix b

$ git cherry -v rel main
- 6eaa3da... fix b
+ a1092a2... fix c

The log lists both as missing. git cherry compares patches and marks an equivalent one with -. Its manual says the test is based on the diff, after removing whitespace and line numbers.

Where the patch comparison fails#

The second fixture picks a fix onto a release branch whose neighboring line differs. The pick conflicts, and the resolution keeps the fix. Its patch now has different context:

$ git cherry -v rel main
+ 12d2232... fix l2

The fix is on the branch, and the command says it is not. The -x line still connects the two, since the picked commit's message ends with:

(cherry picked from commit 12d2232b57c782043a5eeee38fb41b4fe22ab050)

So the two sources have opposite weaknesses. Both were run with Git 2.43.

Says pickedSays missing
git cherryAn equivalent patch is thereMissing, or adapted during a conflict
-x lineSomeone picked that commit, perhaps adapting itMissing, or picked without -x, or the line was edited out

Neither one tells you whether the fix works on the release branch. A commit can be picked and later reverted, and both lists still count it.

Build the list to hand over#

git cherry -v rel main | grep '^+' > open.txt
git log rel --not main --format='%h %s%n%b' | grep -E '^[0-9a-f]{7,} |cherry picked from'

For each line in open.txt, look for its ID in the second output. Then sort what is left:

StateNext decision
Equivalent patchNone, unless it was reverted later
Marked +, with an -x lineRead the adapted pick and run its test on the release branch
Marked +, with no -x lineDecide whether to backport, and say why not if you skip it

Search for reverts with git log rel --grep='^Revert' --oneline.

Worked example#

This example is fictional. Ana hands Ben the 4.2 branch before her leave. Her note says "all security fixes are in". Ben runs git cherry and finds six + lines. Four have -x lines in adapted commits, whose tests pass on the branch. One is a documentation change. The sixth has neither, and its advisory covers 4.2. Ben's decision is one backport, and the note he adds to the branch lists all six with the reason for each.

If the fix has to travel without a shared remote, send it as a patch with its base. Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading