Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've used the basic functionalities of SVN before to check in code and check it out. I've never touched branches and more complex stuff like that. Is it possible to use SVN so I can keep a master version of a source code file, make a slightly different version of it for a different project, and then have any changes to the master version be copied to the other versions without overwriting the changes made to those other versions?

I kind of doubt this is possible to easily deal with without having to manually deal with conflicts, so let me ask an alternative question: If I made a repository with a sort of common library of code and then made any project specific changes to that in separate files using class inheritance, is it possible to set it up so there are two repositories checked out in the same folder?

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

This is a difficult thing to do in SVN. It requires a lot of manual merging and is prone to errors. However, if you have the option, like @Ash mentions, distributed version control systems handle this scenario quite well. In particular, I know that Git makes this extremely easy.

The git-rebase command does exactly what you want. Assuming you have a main or "origin" branch of your source, you just make a new branch ("mywork") to make your project specific changes on(represented by block C6).

Now, as the main branch of the code continues to change (revision C3 & C4), you just rebase your project specific branch to the new revision and you will get all of the changes that have been made on the main branch in you project's branch.

There is still a possibility of having to do a manual merge, but the likelyhood of having to do it is much lower. Git takes a lot of the pain out of performing the merge operation. Check out the Git Book's rebasing chapter for more info.

share|improve this answer
add comment

I think this is pretty difficult to do with subversion (at least current versions), if not impossible, but a distributed version control system will handle it. I've used Mercurial to solve this problem:

On the "server" side:

  • Create a "master" repository
  • Clone that repository to make the project specific version of the repository (cloning is making a duplicate of an entire repository somewhere else)

On the "client" side:

  • Clone the project repository to your development area and check it out
  • Make changes, comitting locally a lot and pushing back to the server as appropriate

If changes to the master occur, they can be "pulled" into the project specific repository, which will flow down to the local repository. If changes made to the project specific repository are deemed suitable for the "master", they can be pushed back up to it. Mercurial remembers the paths between parent repositories, so it all fits together. Merges between branches (which you tend to use a lot more) and repositories are generally pain free. One disadvantage is that Mercurial doesn't allow "cherry picking" of updates, but that can be an advantage since it keeps you out of potential trouble in future merges.

There's probably a bigger a learning curve in doing all this, but might be worthwhile to investigate.

share|improve this answer
add comment

The short answer is "no". The problem you describe is merging the branches when there's a change. There are tools that will assist but in the end you're merging two branches of code that have both changed. This situation may cause a conflict which will require human intervention.

share|improve this answer
add comment

Isn't this question much better asked over on SO (which has over 5,000 SVN questions)? I see there are some SVN questions here, but I don't know what makes one better suited for either site.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["        <li><a href=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.3.12.1446\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Super User works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </noscrip"], "copyright__copyright__copyright": ["ch will require human intervention.\n\nshare|improve this answer\nadd comment\n\nIsn't this question much better asked over on SO (which has over 5,000 SVN questions)? I see there are some SVN questions here, but I don't know what makes one better suited for either site.\n\nshare|improve this answer\nadd comment\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}