简体   繁体   English

合并后重用开发分支

[英]Reuse a develop branch after merge

Git newbie here! Git新手在这里! Here's the scenario: app built in Laravel + Envoyer for deploying.场景如下:应用内置 Laravel + Envoyer 进行部署。 So I have a master / develop branches, the first one deploying to site.com and the other one to dev.site.com所以我有一个 master / develop 分支,第一个部署到 site.com,另一个部署到 dev.site.com

I've developed a new feature on develop branch and tested on dev.site.com.我在开发分支上开发了一个新功能并在 dev.site.com 上进行了测试。 So I've merged the develop branch into the master branch.所以我已经将开发分支合并到主分支。 Now it seems that the develop branch is not active anymore (any change affects the master branch and viceversa).现在似乎开发分支不再活跃(任何更改都会影响主分支,反之亦然)。 In other words they're not separate anymore.换句话说,他们不再分开了。

I've read that reusing a branch after a merge is not a good practice but, in this specific case, I need to have a branch called "develop" again.我读过在合并后重用分支不是一个好习惯,但在这种特定情况下,我需要再次有一个名为“develop”的分支。

I've tried deleting the develop branch and create a new one with the same name (as suggested here ) with no success: it seems that the old develop branch is restored.我试过删除 develop 分支并创建一个同名的新分支(如建议here )但没有成功:似乎旧的 develop 分支已恢复。

Any advice?有什么建议吗?

Screenshot from bitbucket来自 bitbucket 的截图

You want to merge master to develop branch.你想合并 master 来开发分支。 For this, run为此,运行

git checkout develop
git merge master
git log

Now you can see that your develop branch contains all commits from master branch, including the commint when you merged develop to master.现在您可以看到您的 develop 分支包含来自 master 分支的所有提交,包括您将 develop 合并到 master 时的提交。 And you can develop in develop branch as usual.您可以像往常一样在开发分支中进行开发。

See also this question: Git reuse branch or delete and create again另请参阅此问题: Git 重用分支或删除并再次创建

In git branches are lightweight.在 git 中,分支是轻量级的。 You can think of a branch as of just a label or a pointer to a particular commit X. When you "commit to a branch", it associates the old tip commit with the new commit with a parent-child relationship, and advances the branch pointer.您可以将分支视为一个标签或指向特定提交 X 的指针。当您“提交到分支”时,它将旧的提示提交与具有父子关系的新提交相关联,并推进分支指针。 The relationship is stored in the commit, it is separate from the branch label existence.关系存储在提交中,它与分支标签分开存在。

Each commit might have multiple parents.每个提交可能有多个父项。 This is what happened when you merged: it made a new commit M with 2 parents (called "merge commit").这就是您合并时发生的情况:它使用 2 个父项进行了新的提交 M(称为“合并提交”)。 At that point in time (if it was done right) you probably had your "master" branch pointing to the merge commit M, and your "develop" branch still pointing to your latest dev commit (I assume it is 83bebd6 if the blue branch is "develop").在那个时间点(如果做得对),您的“主”分支可能指向合并提交 M,而“开发”分支仍指向您最新的开发提交(如果蓝色分支,我认为它是 83bebd6是“发展”)。

Now, to find out if your branches diverge or not, you can run:现在,要了解您的分支是否有分歧,您可以运行:

git show master
git show develop

This will show a commit that each branch is pointing at (again think in terms of labels to commits).这将显示每个分支指向的提交(再次考虑提交的标签)。

To know which branch you are currently at, you run git branch .要知道您当前所在的分支,请运行git branch If you are currently at "master", it means that each commit will advance and update the master "label" (and it will "diverge" from whatever other branches you have as soon as you commit, because normally you can't commit to multiple branches at a time).如果您当前处于“master”,则意味着每次提交都会推进并更新master “标签”(并且一旦提交,它将与您拥有的任何其他分支“发散”,因为通常您无法提交一次有多个分支)。

Although it's a dangerous and destructive operation, you can always "reset" your branch "label" to point to some other (previous or even totally unrelated) commit:尽管这是一个危险且具有破坏性的操作,但您始终可以“重置”分支“标签”以指向其他(以前的甚至完全不相关的)提交:

git checkout develop
git reset --hard 83bebd6

This will locally make so that "develop" points to commit 83bebd6.这将在本地进行,以便“开发”指向提交 83bebd6。

If you want this branch to reset on the bitbucket server (and this is even more dangerous and destructive), you do:如果您希望此分支在 bitbucket 服务器上重置(这更加危险和破坏性),您可以:

git push -f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM