[英]Git branching from another branch
I am trying to make sure I don't mess up a large feature branch I have been working on. 我试图确保我不会弄乱我一直在努力的大型功能分支。 I have two remotes:
我有两个遥控器:
origin - with branch dev
my - a fork of origin, with my branch dev
So, workflow is to fetch origin, pull into my origin dev, branch from that, push up, and merge branches into origin dev: 因此,工作流程是获取原点,放入我的原点开发器,从中进行分支,上推,然后将分支合并到原点开发中:
# On my dev
git fetch origin
... received new stuff...
git pull origin dev
I had a feature which depended an un-merged other branch feature. 我有一个依赖于未合并的其他分支功能的功能。 So, I did this:
因此,我这样做:
# On my dev
git checkout -b first-feature
git checkout -b second-feature-based-on-first-feature
From here, I've been following our normal workflow, where when origin dev is updated, we rebase our branch on that: 从这里开始,我一直遵循正常的工作流程,在该工作流程中更新了origin dev之后,我们以此为基础重新建立分支:
git checkout first-feature
git pull --rebase origin dev
git push my first-feature -f
And then I would pull that first branch under my second branch: 然后我将第一个分支拉到第二个分支下:
git checkout second-feature-based-on-first-feature
git pull --rebase my first-feature
git push my second-feature-based-on-first-feature -f
Today first-feature was merged into origin dev. 今天,第一功能已合并为原始开发人员。 I expected second-feature's pull request on github, which showed two commits (first-feature and second-feature), to basically just now show second-feature.
我期望在github上显示第二个功能(第一功能和第二功能)的github上的第二功能的pull请求,基本上现在才显示第二功能。 But it doesn't.
但事实并非如此。 I rebased second-feature on origin dev, and while everything seems okay, I am worried about this.
我将第二功能基于origin开发,尽管一切似乎还不错,但我对此感到担心。 Do I just force push second-feature up?
我只是强行将第二功能推高了吗?
I know this is a bit specific. 我知道这有点具体。 I suppose my question is: how should this work, and where have I gone wrong (if I have)?
我想我的问题是:这应该如何工作?我在哪里出错了(如果有的话)? I tried to follow other answers to basing a branch off a branch, but this is such unfamiliar territory, I don't want to make a huge mistake.
我尝试遵循其他答案以将分支从分支下立,但这是一个如此陌生的领域,我不想犯一个大错误。
I think the problem you are seeing is the side effects of rewriting history. 我认为您看到的问题是重写历史记录的副作用。
When you rebase, it actually changes the commit hash 当您变基时,它实际上会更改提交哈希
The hash of a commit is depending on: 提交的哈希取决于:
So the commits on your first-feature when rebased with origin/master, second-feature was still based on commits from the the original first feature, so when you rebased the second-feature with first-feature, the commits on the first-where different, then the rebase changed the top two commits where changed as well. 因此,在使用原点/母版重新定义基础功能时,对第一功能的提交仍基于原始第一功能的提交,因此,当您使用第一功能对第二功能进行基础化时,则在第一位置进行提交不同的是,然后rebase更改了更改的前两个提交。 So you had:
所以你有:
1) -- A
\ -- B
\ -- C
After rebase origin/dev
2) -- A -- B'
-- A -- B
\ -- C
Rebase with first-feature
3) -- A' -- B' -- B -- C'
At least this is what it appears from your flow you have described. 至少这是从您描述的流程中看到的结果。 I hope this helps!
我希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.