开发者

GIT - branches not closing after merge

开发者 https://www.devze.com 2023-03-24 00:58 出处:网络
we are pretty unexperienced in using GIT. Actually we like the idea of branches ;-) But somehow all merges from one user just don\'t close the branch...

we are pretty unexperienced in using GIT. Actually we like the idea of branches ;-) But somehow all merges from one user just don't close the branch...

You can look at the image here: http://i54.tinypic.com/297i14.png

There is a grey and a blue line which just got straight forward... eve开发者_高级运维n after the merge... So what is he doing wrong? Any clues? I don't want imagin what happens if he creates some more branches and all of them persist in the history view even after a merge...

Thank you very much!


When you do a merge, the new commit only moves forward your current branch. The branch name that pointed to the other branch is left where it was. In other words, if you have this situation:

A---B---C blue
 \
  D---E---F grey

... and do:

git checkout blue
git merge grey

You'll end up with:

A---B---C---G blue
 \         /
  D---E---F grey

If you want to remove the grey branch you can then do git branch -d grey. This won't affect the commit graph, just remove the branch - they're like labels that get moved around the commit graph.

However, if you carry on and create more commits on the grey and blue branches, those lines will continue:

A---B---C---G---H---I blue
 \         /
  D---E---F---J---K---L grey

In the image you link to, I assume that either there are further commits further above the section you've shown, or the tool you're using is just presenting the commit graph strangely.


I am not certain what you mean by closing the branch, but I'll make a guess :)

It is still possible to use a branch even after a merge has been done. I guess this is per design and how it should be. For instance you might want to continue working with the branch even after a merge has been done, say in order to continue focusing on development in that branch. That is why it still shows up in the image you referred to.

If you don't want to do that, it is possible to delete the branch after merging, which closes it definitively by issuing the command git branch -d <branch> while being in another branch, like master. (This will only delete the branch if its latest commit has been merged with the branch you have active, so there is no risk of losing data.)


Currently git requires a two step process for the merging and closing of a 'task' branch where the merge nominally indicates closure of the task and that the branch is no longer required.

It maybe that it would be a useful option for some to be able to delete a branch's refs/heads entry so closing everything in one step [make a proposal to the git list?]. However I'm sure that many workflows have instances where they want the ability to go back and tidy up some minor issue, which an early deletion would make awkward. (though it would be in the reflog for a while)

Give the user the task of creating an alias or script to combine the two actions. It will help the education all round ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消