如何关联两个不同代码仓库中解决同一问题的提交?
Great question! When you’ve got two changes in separate repos that work together to fix the same problem, there are a few straightforward ways to tie them up so reviewers can easily see their connection:
1. Reference Each Other's Change-Id in Commit Messages
Every Gerrit change gets a unique Change-Id (looks like Iabcdef123456789) once you push it to the server. You can add a reference to the other change's ID in both commit messages using tags like Related: or Depends-On: (use Depends-On: if one change requires the other to be merged first to work correctly).
Example Commit Message for Repo A:
Fix broken payment processing flow This change updates the checkout service in repo-A to handle the new invoice schema. Related: I987654321fedcba (repo-B's change that defines the new invoice schema) Change-Id: Iabcdef123456789
Example Commit Message for Repo B:
Define new invoice schema for payment system This change introduces the updated invoice structure in repo-B, which repo-A relies on for checkout. Related: Iabcdef123456789 (repo-A's change that implements the new schema) Change-Id: I987654321fedcba
If you already pushed the changes and need to add this reference later, you can:
- Use
git commit --amendto edit the commit message locally, then force-push withgit push origin HEAD:refs/for/branch-name%edit - Or, edit the commit message directly in the Gerrit web interface (many projects allow this via the "Edit" button near the change title)
2. Cross-Reference in Gerrit Comments
Open either change's Gerrit page, and in the comment section, mention the other change using its full URL or just the Change-Id. Gerrit automatically turns these into clickable links.
For example, in repo-A's change comment:
Heads up: This change pairs with repo-B's change
I987654321fedcbato fully fix the payment processing issue. Both need review and merge together.
3. Use Gerrit's Dependency Tracking (If Applicable)
If one change can't work without the other (e.g., repo-A's code uses a new feature added in repo-B), use the Depends-On: tag instead of Related:. Gerrit will show a clear dependency link, and some projects configure it to block merging the dependent change until the upstream one is merged.
This makes it crystal clear to reviewers and maintainers that the two changes are part of a single solution.
内容的提问来源于stack exchange,提问作者fabatera

