Git:如何在同一分支中的提交之上重新建立分支? [英] Git: how to rebase a branch on top of a commit in the same branch?

查看:254
本文介绍了Git:如何在同一分支中的提交之上重新建立分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用这个出色的答案,我阅读并(我认为)理解了,但据我所知不能回答我的特定问题(因为它解释了如何基于不同分支中的提交,但是我想基于同一分支).

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).

情况

  • 有两个分支,masterfeaturefeature在某些时候基于master
  • 重新建立
  • 后来,出于任何原因*,我们希望featuremaster的先前提交之一中分支"出来.
  • There are two branches, master and feature, feature at some point gets rebased on top of master
  • Later, for whatever reason* we want feature to "branch out" from one of the previous commits of master

(* * 原因,例如:将本地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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆