git 更改分支的原点(rebase)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10976938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git change origin of a branch (rebase)
提问by VonC
f'I have the following:
f'我有以下几点:
A---B---C-----D-- branch dev
\--C'-E-/ branch test
I did it bad: C and C' are almost the same commits, it would make more sense if I could make branch teststart on C, instead of B.
我做得不好:C 和 C' 几乎是相同的提交,如果我可以在 C 而不是 B 上开始分支测试会更有意义。
How could I do that?, I guess rebase, but I'm not sure how to use it, thx
我怎么能那样做?,我想是变基了,但我不知道如何使用它,谢谢
edit: wasn't clear what I'd like:
编辑:不清楚我想要什么:
A---B---C-----D-- branch dev
\-E-/ branch test
or
或者
A--B--D--E--D if not possible
A--B--D--E--D 如果不可能
回答by VonC
You could rebase it on top of a temporary branch (made from C
)
See git rebase
and Rebasing, plus git branch
.
您可以在临时分支(由C
)
Seegit rebase
和Rebase以及加上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
That should give you:
那应该给你:
A---B---C-----D-- branch dev
\--C''-E'-/ branch test
I have left C' (here as C'') because C' isn't exactlythe same than C.
But as amscomments, if you need C' gone, you would
我已经离开了 C'(这里是 C''),因为 C'与C 并不完全相同。
但是作为ams 的评论,如果你需要 C' 消失,你会
git rebase -i tmp
That would get you an interactiverebase, allowing for C'
to be removed completely, replaying only E
on top of C
.
这将为您提供交互式变基,允许C'
完全删除,仅E
在C
.
回答by ellotheth
You can rebase just the piece you want onto C:
你可以只将你想要的部分变基到 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
It's the same concept as cherry-picking, except the test
branch pointer moves along with the rebased commits.
它与cherry-picking 的概念相同,只是test
分支指针随着重新提交的提交而移动。
(Note that the C' commit will be unreachable after the rebase, but you can get back to it with git reflog
.)
(请注意,在变基后 C' 提交将无法访问,但您可以使用git reflog
.