Gerrit能否处理跨仓库相互依赖提交并支持同步合并?
Absolutely, Gerrit has built-in features to handle exactly this scenario where your two repository updates are interdependent and must be merged together to ensure a working build. Here are the two most reliable approaches to manage this:
1. Use Shared Topic Branches
Gerrit’s topic branches are designed to group related changes across multiple repositories. When you push your commits to Gerrit, assign the same topic name to both changes, and Gerrit will link them together in its web interface.
- For repo1, when pushing your version2 change:
git push origin HEAD:refs/for/main%topic=version2-cross-repo-sync - Do the exact same for repo2’s version2 change:
git push origin HEAD:refs/for/main%topic=version2-cross-repo-sync
Once pushed, you’ll see both changes grouped under the version2-cross-repo-sync topic in Gerrit. Reviewers can easily view both changes together, and you (or your team’s merge manager) can use Gerrit’s bulk operations to merge both changes at the same time, ensuring they’re synchronized.
2. Explicitly Link Changes with Depends-On
You can also create a direct dependency between the two changes by adding a Depends-On line in one of the commit messages, referencing the other change’s unique Change-Id.
For example, in repo2’s commit message, add:
Depends-On: Iabcdef1234567890abcdef1234567890abcdef1
(Replace Iabcdef... with the actual Change-Id of your repo1 version2 change.)
This tells Gerrit that the repo2 change relies on the repo1 change being merged first. While this doesn’t enforce simultaneous merging by default, it makes the dependency clear to reviewers and merge managers. You can still coordinate to merge both changes in quick succession, or use Gerrit’s batch merge tool to handle them together.
Key Notes to Avoid Issues
- Make sure your team is aware of the dependency: Communicate that neither change should be merged in isolation, as this will break the build.
- Use Gerrit’s web interface to verify the link: Check that the topic or Depends-On relationship is correctly showing up before requesting reviews.
内容的提问来源于stack exchange,提问作者Xiaoquan Li

