git - 如何 git rebase、保留合并和移动所有分支?
问题描述
我们在多个团队中使用 git 进行版本控制。每个团队将功能交付到团队分支(合并)中,如下所示:
* [integration_team1] Merge team1_featureB into integration_team1
|\
| * [team1_featureB] Comment about feature B code
|/
* Merge team1_featureA into integration_team1
|\
| * [team1_featureA] Comment about feature A code
|/
* [release]
(Names in square brackets are branch names.)
我们定期将集成分支交付到 [release] 中,保留历史记录。对于一个团队来说,这很容易:将 [integration_team1] 合并到 [release] 中,快进。但是,当涉及两个或更多团队时,图表可能如下所示:
* [integration_team1][release] Merge team1_featureB into integration_team1
|\
| * [team1_featureB] Comment about feature B code
|/
* Merge team1_featureA into integration_team1
|\
| * [team1_featureA] Comment about feature A code
| |
| | * [integration_team2] Merge team2_featureD into integration_team2
| | |\
| | | * [team2_featureD] Comment about feature D code
| | |/
\ | * Merge team2_featureC into integration_team2
\| |\
\ | * [team2_featureC] Comment about feature C code
\|/
*
我想将 [integration_team2] 重新定位到 [release],保留合并并移动所有分支。如果我做:
git checkout integration_team2
git rebase --rebase-merges release
然后我得到这个图表:
* [integration_team2] Merge team2_featureD into integration_team2
|\
| * Comment about feature D code
|/
* Merge team2_featureC into integration_team2
|\
| * Comment about feature C code
|/
* [integration_team1][release] Merge team1_featureB into integration_team1
|\
| * [team1_featureB] Comment about feature B code
|/
* Merge team1_featureA into integration_team1
|\
| * [team1_featureA] Comment about feature A code
| |
| | * [team2_featureD] Comment about feature D code
| | |
\ | * Merge team2_featureC into integration_team2
\| |\
\ | * [team2_featureC] Comment about feature C code
\|/
*
rebase 的结构是正确的,但相关的分支不会移动。有没有办法移动这些?具体来说,基本技术要求:当为变基处理每个提交时,该提交上存在于远程的任何分支都应移动到新的变基(樱桃采摘)提交。如果这样做,结果将是:
* [integration_team2] Merge team2_featureD into integration_team2
|\
| * [team2_featureD] Comment about feature D code
|/
* Merge team2_featureC into integration_team2
|\
| * [team2_featureC] Comment about feature C code
|/
* [integration_team1][release] Merge team1_featureB into integration_team1
|\
| * [team1_featureB] Comment about feature B code
|/
* Merge team1_featureA into integration_team1
|\
| * [team1_featureA] Comment about feature A code
|/
*
从这一点开始,[release] 分支可以简单地快进,我们有一个干净的历史记录。有没有办法做到这一点,也许使用管道命令?
解决方案
git rebase
仅在当前分支上运行。我能想到的唯一解决方案是单独重置每个分支:
git checkout <branch>
git reset --hard <hash>
您可以从中获取哈希,git log
并使用与原始提交相同的消息查找重新定位的提交。
推荐阅读
- sql - 如何编写查询以使其仅返回两列为零的结果?
- reactjs - react-redux useCallback 无限渲染
- python - Python/MySQL:在原始数据库查询中用作参数的转义字符串
- javascript - Noob Question Repost: How to Turn this into a working link that still uses the data that is recieved from the Id Tag
- amazon-web-services - 通过负载均衡器过滤 *.my-site.com/ 流量并撤消其余流量
- c - STM32 - 为什么代码没有像它应该的那样修改寄存器?
- javascript - 清除包含特定字符串 discord.js 的消息
- android - 如何在颤振中使用 onesignal 修复警告 - 警告:[unchecked] unchecked cast
- python-3.x - 使用 reddit 的 api 如何下载选定的线程?
- sql - 在数据库中的现有表上启用系统版本控制