upstream-patches
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUpstream Patches
上游补丁
upstream/patches/./scripts/upstream.shupstream/patches/./scripts/upstream.shDefault Behavior
默认行为
- If fixing a regression introduced by an existing patch, amend the owning patch commit.
- Do not create a new patch unless the user explicitly asks.
- 如果要修复现有补丁引入的回归问题,请修改对应所属补丁的提交。
- 除非用户明确要求,否则不要创建新补丁。
Commands Reference
命令参考
| Command | Description |
|---|---|
| Initialize upstream and apply patches to working directory |
| Force re-initialize, discarding any changes |
| Create branch with patches as commits for editing |
| Interactively edit patch commits |
| Rebase patches onto a new upstream commit |
| Write commits back to patches and exit checkout mode |
| 命令 | 描述 |
|---|---|
| 初始化上游仓库并将补丁应用到工作目录 |
| 强制重新初始化,丢弃所有变更 |
| 创建包含补丁提交的分支以便编辑 |
| 交互式编辑补丁提交 |
| 将补丁变基到新的上游提交之上 |
| 将提交写回补丁文件并退出检出模式 |
Guardrails
防护规则
- Never commit directly to without
upstream/.checkout/check_in - Direct edits under outside checkout are ephemeral during
upstream/; the tool resets submodule state.upgrade-provider - Do not hand-edit unless intentionally doing raw patch surgery.
patches/*.patch - Prefer non-interactive rewrite flow over interactive rebase for agents.
- 没有执行操作时,永远不要直接提交到
checkout/check_in目录。upstream/ - 检出模式之外对下的直接编辑在
upstream/过程中是临时的;工具会重置子模块状态。upgrade-provider - 除非你故意要进行原始补丁修改操作,否则不要手动编辑文件。
patches/*.patch - 对于Agent来说,优先使用非交互式重写流程而非交互式变基。
Find Owning Patch First
先查找所属补丁
Before editing patch content, identify the owning patch/commit.
bash
./scripts/upstream.sh checkout编辑补丁内容之前,先确定对应的所属补丁/提交。
bash
./scripts/upstream.sh checkoutFind candidate patch files by touched file path or unique hunk text
Find candidate patch files by touched file path or unique hunk text
rg -n "path/to/file|unique_symbol" patches/*.patch
rg -n "path/to/file|unique_symbol" patches/*.patch
Optional: inspect candidate patch header/hunks
Optional: inspect candidate patch header/hunks
sed -n '1,120p' patches/00NN-Example.patch
sed -n '1,120p' patches/00NN-Example.patch
Map patch file to commit in upstream checkout branch
Map patch file to commit in upstream checkout branch
patch=patches/00NN-Example.patch
subject=$(sed -n 's/^Subject: [PATCH] //p' "$patch" | head -n1)
cd upstream
git log --oneline pulumi/patch-checkout --grep "$subject"
patch=patches/00NN-Example.patch
subject=$(sed -n 's/^Subject: [PATCH] //p' "$patch" | head -n1)
cd upstream
git log --oneline pulumi/patch-checkout --grep "$subject"
If needed, disambiguate by touched path
If needed, disambiguate by touched path
git log --oneline pulumi/patch-checkout -- path/to/file
cd ..
Set `target_sha` to the owning commit and edit that commit, not `HEAD`.git log --oneline pulumi/patch-checkout -- path/to/file
cd ..
将`target_sha`设置为所属提交,编辑该提交而非`HEAD`。Amend Existing Patch (Preferred, Non-Interactive)
修改现有补丁(推荐,非交互式)
bash
./scripts/upstream.sh checkout
cd upstream
target_sha=<owning-commit-sha>
base_sha=$(git rev-parse "${target_sha}^")
tmp_branch="rewrite-${target_sha:0:8}"bash
./scripts/upstream.sh checkout
cd upstream
target_sha=<owning-commit-sha>
base_sha=$(git rev-parse "${target_sha}^")
tmp_branch="rewrite-${target_sha:0:8}"Rebuild history from parent of target commit
Rebuild history from parent of target commit
git checkout -b "$tmp_branch" "$base_sha"
git cherry-pick "$target_sha"
git checkout -b "$tmp_branch" "$base_sha"
git cherry-pick "$target_sha"
Apply fix and amend target commit
Apply fix and amend target commit
...edit files...
...edit files...
git add <files>
git commit --amend --no-edit
git add <files>
git commit --amend --no-edit
Replay remaining commits
Replay remaining commits
git cherry-pick "${target_sha}..pulumi/patch-checkout"
git cherry-pick "${target_sha}..pulumi/patch-checkout"
If cherry-pick conflicts occur:
If cherry-pick conflicts occur:
resolve files
resolve files
git add <resolved files>
git add <resolved files>
git cherry-pick --continue
git cherry-pick --continue
Move checkout branch to rewritten history
Move checkout branch to rewritten history
git branch -f pulumi/patch-checkout HEAD
git checkout pulumi/patch-checkout
git branch -D "$tmp_branch"
cd ..
Interactive fallback:
```bash
./scripts/upstream.sh checkout
./scripts/upstream.sh rebase -igit branch -f pulumi/patch-checkout HEAD
git checkout pulumi/patch-checkout
git branch -D "$tmp_branch"
cd ..
交互式回退方案:
```bash
./scripts/upstream.sh checkout
./scripts/upstream.sh rebase -imark target commit as edit, amend, then continue
mark target commit as edit, amend, then continue
undefinedundefinedRemove Entire Patch
移除整个补丁
Use when a patch should be deleted completely.
bash
rm patches/00NN-Description.patch
./scripts/upstream.sh checkout
./scripts/upstream.sh check_in当需要完全删除某个补丁时使用。
bash
rm patches/00NN-Description.patch
./scripts/upstream.sh checkout
./scripts/upstream.sh check_inRemove Part of a Patch
移除补丁的部分内容
Use when only selected hunks/files should be removed from an existing patch.
- Find owning patch/commit () and use the amend workflow above.
target_sha - Revert only unwanted changes from the target commit, then amend.
Example during amend step:
bash
cd upstream当只需要从现有补丁中移除选定的补丁块/文件时使用。
- 查找所属补丁/提交()并使用上述修改流程。
target_sha - 仅撤销目标提交中不需要的变更,然后修改提交。
修改步骤中的示例:
bash
cd upstreamRestore specific docs-only files from parent of amended commit
Restore specific docs-only files from parent of amended commit
git checkout HEAD^ -- path/to/docs-only-file path/to/another-doc-file
git add path/to/docs-only-file path/to/another-doc-file
git commit --amend --no-edit
cd ..
undefinedgit checkout HEAD^ -- path/to/docs-only-file path/to/another-doc-file
git add path/to/docs-only-file path/to/another-doc-file
git commit --amend --no-edit
cd ..
undefinedCreate New Patch (Only If Requested)
创建新补丁(仅在被要求时执行)
bash
./scripts/upstream.sh checkout
cd upstreambash
./scripts/upstream.sh checkout
cd upstream...make changes...
...make changes...
git add <files>
git commit -m "Describe new patch"
cd ..
./scripts/upstream.sh check_in
undefinedgit add <files>
git commit -m "Describe new patch"
cd ..
./scripts/upstream.sh check_in
undefinedRebasing Patches to a New Upstream Version
将补丁变基到新的上游版本
bash
./scripts/upstream.sh checkoutbash
./scripts/upstream.sh checkoutRebase onto the new upstream commit
Rebase onto the new upstream commit
./scripts/upstream.sh rebase -o <new_commit_sha>
./scripts/upstream.sh rebase -o <new_commit_sha>
Resolve any conflicts that arise
Resolve any conflicts that arise
Write updated patch files
Write updated patch files
./scripts/upstream.sh check_in
undefined./scripts/upstream.sh check_in
undefinedVerification Checklist
验证检查清单
Before :
check_in- Confirm expected patch count change (by default;
0for full patch removal).-1 - Confirm whether target patch should remain present (default yes) or be removed (explicit deletion case).
- Confirm you are editing the owning commit, not adding a new commit by accident.
After :
check_in- Verify patch count matches expectation.
- Verify target patch number/purpose is still present when expected.
- Verify no unexpected new was introduced.
00NN-*.patch
If checkout mode is stuck, use to reset.
./scripts/upstream.sh init -f执行之前:
check_in- 确认预期的补丁数量变化(默认是;完全移除补丁的话是
0)。-1 - 确认目标补丁应该保留(默认是)还是被移除(显式删除场景)。
- 确认你正在编辑的是所属提交,而不是意外添加新提交。
执行之后:
check_in- 验证补丁数量符合预期。
- 验证预期保留的目标补丁编号/用途仍然存在。
- 验证没有意外引入新的文件。
00NN-*.patch
如果检出模式卡住,使用重置。
./scripts/upstream.sh init -f