简体   繁体   中英

Reuse a develop branch after merge

Git newbie here! Here's the scenario: app built in Laravel + Envoyer for deploying. So I have a master / develop branches, the first one deploying to site.com and the other one to dev.site.com

I've developed a new feature on develop branch and tested on 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.

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.

Any advice?

Screenshot from bitbucket

You want to merge master to develop branch. 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. And you can develop in develop branch as usual.

See also this question: Git reuse branch or delete and create again

In git branches are lightweight. 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. 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"). 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").

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

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.

If you want this branch to reset on the bitbucket server (and this is even more dangerous and destructive), you do:

git push -f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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