10

f'我有以下内容:

A---B---C-----D--   branch dev
     \--C'-E-/      branch test

我做得不好:C和C'几乎是相同的提交,如果我可以在C而不是B上开始分支测试会更有意义。

我怎么能这样做?,我猜是变基,但我不知道如何使用它,谢谢

编辑:不清楚我想要什么:

A---B---C-----D--   branch dev
         \-E-/      branch test

或者

A--B--D--E--D 如果不可能

4

2 回答 2

10

您可以将其重新设置在临时分支(由 制成C
Seegit rebaseRebasing以及git branch.

git branch tmp C
git checkout test

# rebase the current branch (test) on top of tmp
git rebase tmp  

git branch -d tmp

那应该给你:

A---B---C-----D--       branch dev
         \--C''-E'-/      branch test

我离开了 C'(这里为 C''),因为 C' 与 C 不完全相同
但正如ams评论,如果你需要 C' 消失,你会

git rebase -i tmp

这将为您提供交互式变基,允许C'完全删除,仅EC.

于 2012-06-11T08:54:34.993 回答
8

您可以将您想要的部分重新定位到 C 上:

A---B---C-----D--   branch dev
     \
      C'-E--      branch test

# git rebase --onto [new base] [starting after this commit] [ending at this commit]
git rebase --onto C C' E

A---B---C-----D--   branch dev
         \
          E--      branch test

它与cherry-picking 的概念相同,除了test分支指针随rebased 提交一起移动。

(请注意,在变基后 C' 提交将无法访问,但您可以使用 . 回到它git reflog。)

于 2012-06-11T15:23:20.220 回答