Git:如何在同一分支中的提交之上重新建立分支? [英] Git: how to rebase a branch on top of a commit in the same branch?
问题描述
引用这个出色的答案,我阅读并(我认为)理解了,但据我所知不能回答我的特定问题(因为它解释了如何基于不同分支中的提交,但是我想基于同一分支).
Referencing this excellent answer, which I read and (I think) I understood, but as far as I see does not answer my specific question (because it explains how to rebase onto a commit in a different branch, but I want to rebase on the same branch).
情况
- 有两个分支,
master
和feature
,feature
在某些时候基于master
重新建立
- 后来,出于任何原因*,我们希望
feature
从master
的先前提交之一中分支"出来.
- There are two branches,
master
andfeature
,feature
at some point gets rebased on top ofmaster
- Later, for whatever reason* we want
feature
to "branch out" from one of the previous commits ofmaster
(* * 原因,例如:将本地feature
分支中的更改重新建立到master
后中断,因此请尝试找出在master
上提交的内容是否中断feature
分支,类似于git-bisect
)
(* reason, e.g.: changes in the local feature
branch broke, after rebasing it on to master
, so try to find out, which commit on master
broke the feature
branch, in a similar way as git-bisect
)
问题:如何实现这一目标?
Question: How to achieve this?
插图
如何去做:
G--H--I--J <-- feature
/
A--B--C--D--E--F <-- master
...对此?
G--H--I--J <-- feature
/
A--B--C--D--E--F <-- master
到目前为止的尝试
尝试#1:
git checkout feature
git rebase C
结果:Current branch bug/8985-miniredis is up to date.
不变.
我认为这个结果是很合逻辑的,因为对于git来说,C
也是当前分支"的一部分. (尽管,按照我的观点,当前分支"只是G..J
)
Result: Current branch bug/8985-miniredis is up to date.
Nothing changed.
I think this result is quite logical, because for git, C
is also part of the "current branch". (Although, from my point of view, the "current branch" is only G..J
)
尝试#2:
git checkout feature
git rebase --onto C feature
结果:First, rewinding head to replay your work on top of it...
.然后feature
只是指向C
,其他提交被丢失".我真的不明白这里发生了什么,但是从我的角度来看,git再也不知道feature
是从F
开始的."
Result: First, rewinding head to replay your work on top of it...
. And then feature
simply points to C
and the other commits are "lost". I don't really understand what is going on here, but again, git cannot know that feature
"starts" at F
, from my point of view.
尝试#3:
git checkout feature
git rebase --onto C master..feature
结果:fatal: invalid upstream 'master..feature'
评论中所述这个答案是不可能的,因为git
会自己插入..HEAD
部分.但是可以肯定,必须有某种方法可以实现这一目标吗?
As stated in the comments of that answer, this is not possible, because git
inserts the ..HEAD
part itself. But surely, there must be some way to achieve this?
换句话说,问题:
如果git rebase --onto C master..feature
有效,如何实现?
推荐答案
首先,感谢@YesThatIsMyName为我指明了正确的方向.
First of all, thanks to @YesThatIsMyName for pointing me to the right direction.
第1.a点. 此答案符合我的需求.
Point 1.a. of this answer has what I need.
使用上面的符号,正确的命令如下:
Using the notation from above, the right command is the following:
git rebase --onto C master feature
这篇关于Git:如何在同一分支中的提交之上重新建立分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!