What do “branch”, “tag” and “trunk” mean in Subversion repositories?

前端 未结 16 1361
后悔当初
后悔当初 2020-11-22 11:51

I\'ve seen these words a lot around Subversion (and I guess general repository) discussions.
I have been using SVN for my projects for the last few year

相关标签:
16条回答
  • 2020-11-22 12:21

    In general (tool agnostic view), a branch is the mechanism used for parallel development. An SCM can have from 0 to n branches. Subversion has 0.

    • Trunk is a main branch recommended by Subversion, but you are in no way forced to create it. You could call it 'main' or 'releases', or not have one at all!

    • Branch represents a development effort. It should never be named after a resource (like 'vonc_branch') but after:

      • a purpose 'myProject_dev' or 'myProject_Merge'
      • a release perimeter 'myProjetc1.0_dev'or myProject2.3_Merge' or 'myProject6..2_Patch1'...
    • Tag is a snapshot of files in order to easily get back to that state. The problem is that tag and branch is the same in Subversion. And I would definitely recommend the paranoid approach:

      you can use one of the access control scripts provided with Subversion to prevent anyone from doing anything but creating new copies in the tags area.

    A tag is final. Its content should never change. NEVER. Ever. You forgot a line in the release note? Create a new tag. Obsolete or remove the old one.

    Now, I read a lot about "merging back such and such in such and such branches, then finally in the trunk branch". That is called merge workflow and there is nothing mandatory here. It is not because you have a trunk branch that you have to merge back anything.

    By convention, the trunk branch can represent the current state of your development, but that is for a simple sequential project, that is a project which has:

    • no 'in advance' development (for the preparing the next-next version implying such changes that they are not compatible with the current 'trunk' development)
    • no massive refactoring (for testing a new technical choice)
    • no long-term maintenance of a previous release

    Because with one (or all) of those scenario, you get yourself four 'trunks', four 'current developments', and not all you do in those parallel development will necessarily have to be merged back in 'trunk'.

    0 讨论(0)
  • 2020-11-22 12:22

    I'm not really sure what 'tag' is, but branch is a fairly common source control concept.

    Basically, a branch is a way to work on changes to the code without affecting trunk. Say you want to add a new feature that's fairly complicated. You want to be able to check in changes as you make them, but don't want it to affect trunk until you're done with the feature.

    First you'd create a branch. This is basically a copy of trunk as-of the time you made the branch. You'd then do all your work in the branch. Any changes made in the branch don't affect trunk, so trunk is still usable, allowing others to continue working there (like doing bugfixes or small enhancements). Once your feature is done you'd integrate the branch back into trunk. This would move all your changes from the branch to trunk.

    There are a number of patterns people use for branches. If you have a product with multiple major versions being supported at once, usually each version would be a branch. Where I work we have a QA branch and a Production branch. Before releasing our code to QA we integrate changes to the QA branch, then deploy from there. When releasing to production we integrate from the QA branch to the Production branch, so we know the code running in production is identical to what QA tested.

    Here's the Wikipedia entry on branches, since they probably explain things better than I can. :)

    0 讨论(0)
  • 2020-11-22 12:23

    Now that's the thing about software development, there's no consistent knowledge about anything, everybody seems to have it their own way, but that's because it is a relatively young discipline anyway.

    Here's my plain simple way,

    trunk - The trunk directory contains the most current, approved, and merged body of work. Contrary to what many have confessed, my trunk is only for clean, neat, approved work, and not a development area, but rather a release area.

    At some given point in time when the trunk seems all ready to release, then it is tagged and released.

    branches - The branches directory contains experiments and ongoing work. Work under a branch stays there until is approved to be merged into the trunk. For me, this is the area where all the work is done.

    For example: I can have an iteration-5 branch for a fifth round of development on the product, maybe a prototype-9 branch for a ninth round of experimenting, and so on.

    tags - The tags directory contains snapshots of approved branches and trunk releases. Whenever a branch is approved to merge into the trunk, or a release is made of the trunk, a snapshot of the approved branch or trunk release is made under tags.

    I suppose with tags I can jump back and forth through time to points interest quite easily.

    0 讨论(0)
  • 2020-11-22 12:23

    I found this great tutorial regarding SVN when I was looking up the website of the author of the OpenCV 2 Computer Vision Application Programming Cookbook and I thought I should share.

    He has a tutorial on how to use SVN and what the phrases 'trunk', 'tag' and 'branch' mean.

    Cited directly from his tutorial:

    The current version of your software project, on which your team is currently working is usually located under a directory called trunk. As the project evolves, the developer updates that version fix bugs, add new features) and submit his changes under that directory.

    At any given point in time, you may want to freeze a version and capture a snapshot of the software as it is at this stage of the development. This generally corresponds to the official versions of your software, for example, the ones you will deliver to your clients. These snapshots are located under the tags directory of your project.

    Finally, it is often useful to create, at some point, a new line of development for your software. This happens, for example, when you wish to test an alternative implementation in which you have to modify your software but you do not want to submit these changes to the main project until you decide if you adopt the new solution. The main team can then continue to work on the project while other developer work on the prototype. You would put these new lines of development of the project under a directory called branches.

    0 讨论(0)
提交回复
热议问题