在GIT实验室中,我没有将B(分支)与A(特征)合并,而是将A(特性)与B(分支)合并。下面是我所做的事情的图形表示。我有这个如下所示。有了这个,"Branch A2"
就会合并到"feature B2"
中,这不是我想要的。问题:如果我继续开发,必须继续的分支是"feature B2"
而不是"Branch A2"
Branch A ----A1------ A2 <-- last commit
\ \ (merge into feature)
Branch(feature) B -- -B1- - -- B2 <-- feature now contains Branch "A2" edits.
这就是我想要的。将"feature B2"
合并到"Branch A2"
中;这样,当我继续开发时,它将在"Branch A2"
上而不是"feature B2"
上
Branch(feature) B ----B1------ B2 <-- last feature commit
\ \ (merge into Branch)
Branch A -- -A1- - -- A2 <-- Branch now contains "B2" feature edits.
修复这个问题的最干净的方法是什么,这样我就可以得到场景2并继续在"A2"
分支而不是"B2"
特性分支上工作?从功能上讲,无论您合并A2->B2还是B2->A2,它们都实现了相同的功能!
想到的一种方法是,我可以重命名合并的分支,并将其命名为分支A2。
发布于 2017-07-07 12:03:47
假设您的更改没有被推向上游,我认为
git checkout feature
git reset B1 --hard
git checkout branch
git merge feature
应该这样做,其中B1是合并之前的提交。
想到的一种方法是,我可以重命名合并的分支,并将其命名为分支A2。
不管怎么说,当您“完成”了特性时,在您的情况下,这甚至可能是更干净的解决方案。
git branch -d branch branch-tmp # Delete branch
git branch -m feature branch # Rename feature into branch
发布于 2017-07-07 10:28:29
您应该能够在您的分支中的合并之前恢复到提交(请参阅How to revert Git repository to a previous commit?),然后按照正确的方向重新进行合并。
发布于 2017-07-08 12:36:01
为了其他可能踩在这条线上的人的利益,下面是我的建议。注意:所有操作都是在** Local Repo
中完成的,尽管您可以在Git Lab
中的** remote Repo
中这样做。完成合并后,如原始线程中的图1所示:
git branch <branch name e.g Branch A>
git checkout <branch name eg Branch A>
。现在,您的新签出分支和您的分支B基本上是相同的,因为自从上次合并分支后没有代码更改。git push origin --delete <your remote branch name e.g feature A>
并使用git branch -d <your local branch name e.g feature A>
跟踪它git branch --list
和git branch -a
将其推送到远程回购之前,确认这是否是您想要的。即使您删除了这些分支,也不用担心历史,因为下次提交时,它将显示代码合并了,最近的分支Branch A
将像合并分支一样在其中进行所有更改。它几乎像C语言中的指针一样工作。变量名已经消失,但是由于您复制了指向另一个名称的指针,所以更改的地址仍然完整。https://stackoverflow.com/questions/44977430
复制相似问题