理解您当前的 Git 历史状态有点困难。我将做几个假设(我会详细说明)。如果需要,请自行运行 git log --all --graph --oneline --decorate 来比较和纠正我的假设。
听起来你有这样的情况:
* M1 <- origin/master (with exampleBranch merged)
|\
| | * C30_C74 <- exampleBranch (additional 45 local-only commits)
| |/
| * C0_C29 <- origin/exampleBranch (30 commits, pushed)
|/
* M0
您的本地 exampleBranch 在 M0 之上总共有 75 个提交,C0_C29 的前 30 个提交已经被合并,并且您被要求将 C30_C74 的剩余 45 个提交拆分为单独的独立合并。
有两种功能相同的方法可以做到这一点:
变基
创建anotherBranch 本地exampleBranch 和rebase 以“切断”C30_C74 并将其“重新附加”到M1。
git checkout exampleBranch # move HEAD to C30_C74
git checkout -b anotherBranch # create anotherBranch at HEAD (C30_C74)
git rebase anotherBranch C0_C29 --onto origin/master # rebase anotherBranch from C0_C29 to M1
樱桃采摘
在M1 上创建anotherBranch,并在cherry-pick 上“复制”/“重播”C30_C74 提交到您的本地exampleBranch。
git checkout origin/master # move HEAD to M1
git checkout -b anotherBranch # create anotherBranch at HEAD (M1)
git cherry-pick C0_C29..C30_C74 # cherry-pick the range C0_C29..C30_C74 to HEAD
完成后,您将拥有如下内容:
* D0_D44 <- anotherBranch (identical changes as C30_C74)
* M1 <- origin/master (with exampleBranch merged)
|\
| | * C30_C74 <- exampleBranch (additional 45 local-only commits)
| |/
| * C0_C29 <- origin/exampleBranch (30 commits, pushed)
|/
* M0
您可以将anotherBranch 视为基于master 的新分支并创建新的合并请求。
有关此类事情的精彩互动教程,请查看https://learngitbranching.js.org/
为未来加分
我猜在所有这些提交中只有少数有意义的逻辑更改。通常很难读取 30 或 45 个提交大小的合并请求。 (想象一下,如果你不得不像那样阅读别人的分支!)
继续开发您的 Git-fu,并努力为每个有意义的逻辑更改提交一次。在线查找有关 Git interactive rebase 如何帮助您重组和简化分支中的提交的指南。