views:

306

answers:

11

Consider a situation. I want to commit a changed file to SVN and see that someone else committed the same file after I checked it out, so I have to "update" and merge changes. While I'm doing that someone commits the same file again, so when I try to commit the merged file I have to update again.

Now if other users commit often enough it looks like I will never be able to commit my changes. Is that really so? How is this problem solved in real development environments?

+22  A: 

This is usually viewed as not a technical problem but a "people" problem. It usually indicates a failure in communication among the team, and if you find yourself in this situation, you should discuss with your fellow developers how to better partition your work.

In most cases, as you are finding, it is not practical for developers to be working in the same area of code at the same time without good coordination between them.

If you actually have this happening at such a rate that you can't even commit your changes, you have moved beyond a problem to what sounds like a Denial-Of-Service attack :).

RedFilter
could I suggest "process related problem" maybe?
jldupont
much better choice of words than my early morning attempt!
RedFilter
Yeah, "peopleware" fail. Just strike that guy with your copy of Code Complete 2nd Edition.
Yacoder
+1 _version control is not a collaboration tool_. Solve the collaboration problem amongst your team.
D.Shawley
@Yacoder: LOL! .
RedFilter
You see .. this is where VSS rocks .. exclusive file locking on checkout means that this entire class of issues cannot occur!!!
Peter M
@Peter M: I don't see that as a feature most of the time - that is like locking the kitchen door because you are making tea!
RedFilter
@OrbMan - well if you don't want anyone else to have your tea then its the best thing to do. And while I should have added a sarcasm tag, the comment is still true - when you change from a file locking to a merge-after-the-fact model there are both benefits and detriments to your choice.
Peter M
@OrbMan: If you ask me, Code Complete is a VERY useful book =)
Yacoder
@Peter M - exclusive file locking is only a good solution for the person who manages to grab the lock - everybody else has to wait.A version control system can only draw attention to the fact that many developers are making changes to the same code (by locking them out, or showing merge conflicts). Resolving the problem requires coordination amongst the developers so they don't step on each other's toes.KLEs answer about splitting the file up logically is the only way to address the fundamental problem.
Stephen C. Steel
+9  A: 

First let us suppose it is not a game, or not done otherwise on purpose to make you angry and steal your nice chair while you went out with anger ...
but needed. ;-)


If this happens, the file is complex to merge (big) and updated very often (will also get big).

This file carries too much responsibility, it should be split logically.

For example, we had a unique property file like this, for the whole application. It even crashed Eclipse to compare two versions of the file ! :-) So some developpers would not compare and merge it, but commit overriding other's commit ! We split the file, one property file per module, and the problems went away.

There are usually other problems associated with this one, such as developpers loosing time to find what they want in a huge file. The split solution solves all these problems.


As a temporary solution, you could synchronize with the people so that they give you an open window to merge and commit. But the problem typically keeps appearing until the team solves it definitely. ;-)

KLE
+3  A: 

Whilst it is fairly common for developers to be working on the same file, it hardly ever happens that you need to perform an update twice in a row, because of people committing before you had a chance to finish the merge.

And if that's the case, and you were to have 5 people working on the same file (crazy in its own right), making micro-commits every 5 minutes, I'd say you got other problems you should worry about and need to restructure your code as well as give them (your peers) a right 'bollocking'.

Wim Hollebrandse
+1  A: 

If the file is being comitted that often, maybe it shouldn't be under source control? My test for this is: "Can I always give a meaningful English description of each revision (i.e. a tag)?" - if not, it probably should not be controlled.

anon
If the changes have to be persistent, then the file must be under version control!
Stephen C. Steel
The data in a database is persistent - this doesn't mean it must be version controlled.
anon
+2  A: 

While I do totally agree with @OrbMan, I can suggest using "Get Lock" command, but only as a last resort.

Igor Korkhov
+4  A: 

You might try creating your own branch and developing against that. Once you have completed your feature, then merge your branch back into the head. This way you defer your merge activities until your work is complete. It doesn't solve your problem -- you still have to do the merge -- but it does defer it and let you get on with your work. Perhaps if everyone on the development team followed this practice -- or something similar with branches only for people working on the same areas -- you'd have fewer issues with the files changing all the time in the main development branch.

tvanfosson
That's a good point - I would just add that the communication issue should still be addressed, else there will likely be a very nasty merge session at some point down the road.
RedFilter
+7  A: 

Couldn't you just lock the file?

from the svn book http://svnbook.red-bean.com/en/1.5/svn.advanced.locking.html

svn lock banana.jpg -m "Editing file for tomorrow's release."
mozillalives
This just changes the technical symptoms of the fundamental people/process problem. Now you complain "I can never commit changes to this file because somebody else always has it locked."
Stephen C. Steel
Don't lock files before you talk to your teammates, because lock can be seen as "I'm working on a way-way more important things, than you, guys".
Yacoder
Obviously this is not a fix for actually talking with your team (but I love how our first assumption as programmers is that we don't need to talk with anyone else). This is simply meant to help him and his team better control who is updating the file.
mozillalives
+3  A: 

OrbMan is right to say that this is a people problem, and you need to find a better way of working. However, it may also point to an underlying architectural issue. It is a bad idea to have a file which needs to be changed so often by so many different developers.

APC
+2  A: 

Although I agree with OrbMan - if the file is being updated so quickly that you can't get your changes in, the underlying issue is one of developer communication - there is a technical solution.

SVN does support the concept of locking a file. You could try locking the file so that others cannot commit whilst you are merging you changes. When you commit your changes, you unlock the file and all should be OK.

That said, SVN does allow people to break locks. In case someone locked a file and forgot to unlock it before going on holiday, for example. So even if you do lock it, someone could break the lock and commit their code before your done merging. But if someone breaks a named users lock and commit without checking with them first, that is probably an even worse example of lack of inter-developer communication and again is more of a "people" problem.

Grhm
+2  A: 

You are looking at the problem as if the situation for those other users is somehow different from yours. It is not: the problem will affect not only yourself, but all those other users, too.

It's not as if those other users were members of an elite group that can only cause the problem, but never experience it itself.

In other words:

If other users commit often enough that you will never be able to commit your changes because you have to constantly update, then other users will not be able to commit their changes, either, because they will have to constantly update themselves. This will slow down all commits to a point where at any given time someone will be able to commit his changes without having to update, including yourself.

tl;dr: the problem will fix itself.

RegDwight
+1  A: 

This is not a solution, but a workaround: use git-svn as a local client to Subversion repository.

Jakub Narębski
Changing to git doesn't really address the issue: whatever version control system you use, you are going to have to reconcile your changes with other peoples changes. You can defer this, but that just turns frequent small annoyances into infrequent large annoyances.
Stephen C. Steel
@Stephen: The advantage of git is that it uses *commit-then-merge* (or *commit-update-recommit* aka rebase), where you first save your changes and then reconcile, as opposed to Subversion *update-before-commit* where you need to reconcile before being able to save your state.
Jakub Narębski
@Jakub Yes, git may make a minor improvement to the mechanics of the operation. However, the fundamental problem of having to review the mechanical merge result for sanity must still be done by the programmer at some point. Using git may be a slightly better workaround, but KLE's suggestion to split the file logically IS a solution (and it works with all version control systems).
Stephen C. Steel