How to use SVN, Branch? Tag? Trunk? [closed]
I was googling around a little bit and couldn't find a good "beginners" guide to SVN, not in the meaning of "how do I use the commands" rather; How do I control my source code?
What I'd like to clear up is the following topics:
- How often do you commit? As often as one would press Ctrl + s?
- What is a Branch and what is a Tag and how do you control them?
- What goes into the SVN? Only Source Code or do you share other files here aswell? (Not considered versioned files.. )
I don't have any idea what branch and tag is so I don't know the purpose, but my wild guess is that you upload stuff to the trunk and when you do a major build you move it to the branch? So, what is considered a major build in this case?
I asked myself the same questions when we came to implement Subversion here -- about 20 developers spread across 4 - 6 projects. I didn't find any one good source with ''the answer''. Here are some parts of how our answer has developed over the last 3 years:
-- commit as often as is useful; our rule of thumb is commit whenever you have done sufficient work that it would be a problem having to re-do it if the modifications got lost; sometimes I commit every 15 minutes or so, other times it might be days (yes, sometimes it takes me a day to write 1 line of code)
-- we use branches, as one of your earlier answers suggested, for different development paths; right now for one of our programs we have 3 active branches: 1 for the main development, 1 for the as-yet-unfinished effort to parallelise the program, and 1 for the effort to revise it to use XML input and output files;
-- we scarcely use tags, though we think we ought to use them to identify releases to production;
Think of development proceeding along a single path. At some time or state of development marketing decide to release the first version of the product, so you plant a flag in the path labelled '1' (or '1.0' or what have you). At some other time some bright spark decides to parallelise the program, but decides that that will take weeks and that people want to keep going down the main path in the meantime. So you build a fork in the path and different people wander off down the different forks.
The flags in the road are called 'tags' ,and the forks in the road are where 'branches' divide. Occasionally, also, branches come back together.
-- we put all material necessary to build an executable (or system) into the repository; That means at least source code and make file (or project files for Visual Studio). But when we have icons and config files and all that other stuff, that goes into the repository. Some documentation finds its way into the repo; certainly any documentation such as help files which might be integral to the program does, and it's a useful place to put developer documentation.
We even put Windows executables for our production releases in there, to provide a single location for people looking for software -- our Linux releases go to a server so don't need to be stored.
-- we don't require that the repository at all times be capable of delivering a latest version which builds and executes; some projects work that way, some don't; the decision rests with the project manager and depends on many factors but I think it breaks down when making major changes to a program.
* How often do you commit? As often as one would press ctrl + s?
As often as possible. Code doesn't exist unless it is under source control :)
Frequent commits (thereafter smaller change sets) allows you to integrate your changes easily and increase chances to not break something.
Other people noted that you should commit when you have a functional piece of code, however I find it useful to commit slightly more often. Few times I noticed that I use source control as a quick undo/redo mechanism.
When I work on my own branch I prefer to commit as much as possible (literally as often as I press ctrl+s).
* What is a Branch and what is a Tag and how do you control them?
Read SVN book - it is a place you should start with when learning SVN:
- What's a Branch?
- Tags
* What goes into the SVN?
Documentation, small binaries required for build and other stuff that have some value go to source control.
Commit frequency depends on your style of project management. Many people refrain from committing if it'll break the build (or functionality).
Branches can be used in one of two ways, typically: 1) One active branch for development (and the trunk stays stable), or 2) branches for alternate dev paths.
Tags are generally used for identifying releases, so they don't get lost in the mix. The definition of 'release' is up to you.
I think the main problem is the mental picture of source control is confused. We commonly have trunk and branches, but then we get unrelated ideas of tags/releases or something to that affect.
If you use the idea of a tree more completely it becomes clearer, at least for me it is.
We get the trunk -> forms branches -> produce fruit (tags/releases).
The idea being that you grow the project from a trunk, which then creates branches once the trunk is stable enough to hold the branch. Then when the branch has produced a fruit you pluck it from the branch and release it as a tag.
Tags are essentially deliverables. Whereas trunk and branches produce them.
As others have said, the SVN Book is the best place to start and a great reference once you've gotten your sea legs. Now, to your questions ...
How often do you commit? As often as one would press ctrl + s?
Often, but not as often as you press ctrl + s. It's a matter of personal taste and/or team policy. Personally I would say commit when you complete a functional piece of code, however small.
What is a Branch and what is a Tag and how do you control them?
First, trunk is where you do your active development. It is the mainline of your code. A branch is some deviation from the mainline. It could be a major deviation, like a previous release, or just a minor tweak you want to try out. A tag is a snapshot of your code. It's a way to attach a label or bookmark to a particular revision.
It's also worth mentioning that in subversion, trunk, branches and tags are only convention. Nothing stops you from doing work in tags or having branches that are your mainline, or disregarding the tag-branch-trunk scheme all together. But, unless you have a very good reason, it's best to stick with convention.
What goes into the SVN? Only Source Code or do you share other files here aswell?
Also a personal or team choice. I prefer to keep anything related to the build in my repository. That includes config files, build scripts, related media files, docs, etc. You should not check in files that need to be different on each developer's machine. Nor do you need to check in by-products of your code. I'm thinking mostly of build folders, object files, and the like.