Subversion: merging files that have (temporarily) gone out of version control
I find myself often working with people who are not particularly version control-savvy, so the following use case for Subversion would be very useful, if I knew the magic words.
- I commit my latest version, note the revision R
- I email a file off to a collaborator and carry on working, possibly committing more changes as I go
- When I get the file back from collaborator, I do a 3-way merge of changes from R to their version into my working copy
It seems like branching et开发者_StackOverflow中文版c is a bit heavyweight for this, but I'm open to any suggestions of good ways to get the job done.
It looks like @Martinho Fernandes gave you a good answer, but I'd like to point out that branching in Subversion is not heavyweight at all. It's a cheap, simple, constant-time-and-space copy operation. Using a branch might make the process a little less error-prone:
- When you are wanting to send to your contributor,
svn cp
the code to a new branch. If you follow the "canonical" repository structure, this would be something likesvn cp http://your-repository.com/trunk/ http://your-repository.com/branches/some-name
. - Optionally, use
svn export
to get a copy of your code to give to your contributor. - Keep on working in the trunk.
- When you get the code from your contributor, make sure you have check in any of your changes to trunk, or this next step won't work like you expect.
- From the root directory of your working copy,
svn switch http://your-repository.com/branches/some-name
. - Copy your contributor's code over your working copy and check it in.
svn switch http://your-repository.com/trunk
- Now, you merge the changes in the last branch commit into your working copy. This can be the trickiest step if you're not used to it, but once you know how, it's pretty straightforward. See this documentation on merging to get started.
I know this doesn't seem quite as simple as not using branching and merging, but once you get the hang of it, you probably won't want to do this any other way (while using Subversion, at least).
There could be a simpler solution, but this should work:
- Start with your working copy clean (i.e., no local changes)
- Go back to the revision R you previously took note (maybe write it somewhere in the e-mail)
- Copy your collaborator's changed file over the file in your working copy@R
- Update to the latest revision, merging your changes in
- Commit the merged changes
精彩评论