[英]Rewriting history after merging feature branch into master
On a personal project that I am working on, I have the following situation - 在我正在进行的个人项目中,我遇到以下情况-
N' <-- mainscreen
/
| N--O--P--Q <-- database
|/
A---B---C---D---------------------M <-- master
\ /
F--G--H--I--J--K--L <-- loginscreen
Now although I have some basic level of experience with git, I never knew about any good git practices nor have I ever worked on a big complex project before which has led my skills to stagnate. 现在,尽管我对git有一些基本的经验,但是我从不了解任何良好的git实践,也从未从事过一个大型复杂项目,在此之前,我的技能一直处于停滞状态。 So I decided to learn it properly and follow some good practices with this project.
因此,我决定适当地学习它,并遵循此项目的一些良好做法。 A quick search led me to this which I guess is a popular model from all the references to it.
快速搜索使我想到了这一点 ,我认为从所有对其的引用中,它是一个受欢迎的模型。
After going through the article, I realized that due to lack of planning in my commits, some of the code in the loginscreen
branch is actually common code required in the other branches and should be kept separate. 阅读完这篇文章后,我意识到由于我的提交中缺乏计划,
loginscreen
分支中的某些代码实际上是其他分支中所需的通用代码,因此应分开存放。 So I decided to rewrite the history of the branch so that the common code is separated out into a new develop
branch. 因此,我决定重写分支的历史记录,以便将通用代码分离到一个新的
develop
分支中。 I found that interactive rebasing can be used to split the commits but I am not sure if that is possible here because I have already merged loginscreen
into master (which was probably a bad idea). 我发现可以使用交互式重定基础来拆分提交,但是我不确定在这里是否可行,因为我已经将
loginscreen
合并到了主loginscreen
(这可能是个坏主意)。 Basically what I want to do is - 基本上我想做的是-
develop
based on A, the initial commit develop
loginscreen
is in its own branch and the common code is in develop
loginscreen
相关的代码在其自己的分支中,而通用代码在develop
loginscreen
into develop
loginscreen
合并到develop
database
and mainscreen
branches on the new develop
branch develop
分支上重新develop
database
和mainscreen
分支 The result should be something like this - 结果应该是这样的-
A-----------------------M----------- <-- master
\ | N--O--P--Q <-- database
\ |/
B---C---D---G--I--K--L <-- develop
\ / \
F---H---J \ <-- loginscreen
\
N` <-- mainscreen
(G, I, K commits contain the common code)
Like I said, this is a personal project and hasn't been pushed yet so there will be no issues in rewriting the history. 就像我说的那样,这是一个个人项目,尚未得到推动,因此重写历史记录不会有任何问题。 But is this even possible?
但这有可能吗?
I easily solved this using cherry-pick. 我可以轻松地解决这个问题。 All I needed to do was create a new branch called
develop
on the initial commit then cherry-picked B,C and D. Then I created a new branch for the loginscreen
commits and cherry-picked, separated the files, merged the branches and solved merge-conflicts as and when necessary. 所有我需要做的就是创建一个名为新的分支
develop
的初始提交,然后樱桃采摘B,C和D.然后我创建了一个新的分支loginscreen
承诺和樱桃采摘,分离文件,合并分支机构和解决必要时合并冲突。 All this resulted in a state somewhat like this - 所有这些都导致了这样的状态-
A---------------------------------- <-- master
\
\
B---C---D--G--I--K--L--------------Q <-- develop
\ \ / \ /
F---H---J M--N--O--P <-- loginscreen
After this, adding the mainscreen
and database
branches was simple cherry-picking of the commits into their respective new branches on develop
. 之后,添加
mainscreen
和database
分支很简单, mainscreen
将提交提交到各自的develop
分支即可。
Bear in mind that this will change the commit timestamps and sometimes the author timestamps(when a conflict occurs). 请记住,这将更改提交时间戳,有时还会更改作者时间戳(发生冲突时)。 I did not bother with the commit ones but the author timestamps can be changed using
git commit --amend --date
. 我没有理会提交者,但是可以使用
git commit --amend --date
更改作者时间戳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.