问题
When you branch some code, finish working with the branch, and merge it back to the trunk, what do you do with the branch? Delete it from the repository? Keep it for reference?
It seems like you would keep it for reference, but I imagine the /branches
directory could get pretty cluttered.
(If this isn't something people generally agree on, please comment and I'll make it a community wiki.)
Clarification
jleedev
is right - we should specify which version control system we're talking about.
I had Subversion in mind, but would love to hear responses regarding other systems, too. Please specify which one you're answering about, or, <bribery>if you want to get the accepted answer</bribery>, compare and contrast several systems.
回答1:
I remove reintegrated branches since I do not need them any more. Git and Mercurial keep branching/merging history anyway. In subversion I'd keep old branches to have a reference to commit history.
回答2:
Answering my own question much later
Now that I use Git, yes, I do delete branches when I'm finished with them. This is because in Git, a branch is nothing more than a label pointing to a specific commit.
When I first heard that, I didn't quite understand, but it's literally true. If you go into a project which you've got under Git version control and open .git/refs/heads
, you will see one file for each branch you have, including master. Each file contains the hash of a commit. That's it.
Obviously, creating such a file is very cheap, which is why branching is cheap in Git. That, in turn, is why I can branch often, and it would be silly to have branches like add_bells_to_the_widget
piling up everywhere.
Once a branch is merged into master, its commits are part of the master branch's history. The only purpose of keeping the branch would be to know which commit I considered that last one on a branch. And that's not very relevant to me when the code is in production.
回答3:
I always prefer keeping the branches. Yes, I can use them as reference, or simply retrieve certain version any time.
回答4:
SVN users generally tag
branches to keep the branches directory clean, no?
回答5:
In every project I work on we delete the dev branches as soon as we're done with them. We do however branch the code when we release and hold on to those for a while
回答6:
I've never deleted branches, but consider it a matter of personal taste. You're not actually deleting the revisions from the repository when you delete the branch.
回答7:
If there is any chance the branch will have a life of its own, obviously you keep it. If not, i would probably keep it but revoke write access. Disks are cheap.
来源:https://stackoverflow.com/questions/2510852/version-control-delete-branches-after-merging