snoofkin
snoofkin

Reputation: 8895

SVN Committing / Updating repository

I was just wondering about something, I'm working on a project with several other programmers, we all use SVN for the project, I downloaded the svn tree to my local computer, and whenever I update something I commit it, up to now, everything is fine.

What if:

  1. I'm working on my local version, updating stuff in XXX.cpp (version1) while someone else uploads version2 of that XXX.cpp, and then I upload my version, will my "older" version overwrite the newer one?

Thanks,

Upvotes: 1

Views: 92

Answers (8)

Grant Thomas
Grant Thomas

Reputation: 45083

This is one of the main points of version control software, and this is what will happen:

  • Someone checks in file A
  • Someone else tries to check in file A
  • SVN will try to auto-merge the file
    • If all is good, make a coffee
    • Uh oh, conflict detected (needs human intervention)
      • Changes are manually checked and confirmed by the submitter

The last part is where things get tricky - nobody wants to have to do this.

Also, SVN has the terrible habit of sometimes corrupting your source files all by itself when it merges, polluting code with <----- mine and <------ theirs left, right and centre - care needs to be taken in all cases.

There are a bunch or scenarios which could be explained to help educate you in this area, however this covers the general idea and a lot other knowledge will come with experience and practice.

Upvotes: 2

mahadeb
mahadeb

Reputation: 676

Actually 2nd developer don't know whether the file was modified by others or not before his commit. As soon as he do commit, it will give warning for version conflicting (because the file version from which he has done modification it has already been modified by others ).
You can then resolve the conflict BUT I think each developer should do SVN-UPATE before each commit, then you can overcome any unwanted situation.

Upvotes: 0

user492238
user492238

Reputation: 4084

It is recommended, to always update before doing commit.

Upvotes: 1

Tim Hofman
Tim Hofman

Reputation: 1

Most of the time SVN tries to merge the changes. If that is not possible it will give you a message that your commit failed and you need to update your checkout before trying to commit again.

That new update might give you conflicts that needs to be resolved. Though, it will never overwrite previous changes.

Upvotes: 0

SeeSharp
SeeSharp

Reputation: 2800

It won't overwrite it, but your modified version will become the latest revision. You'll need to merge your changes from your working copy to the previous revision.

If you're working on separate logical units with changes to the same code-base I'd recommend you branch your tasks and merge from branch to trunk once completed.

Upvotes: 0

David
David

Reputation: 218798

SVN will do its best to merge the changes both developers have made. If you're working in different parts of the file, it'll most likely handle this without a problem. If both developers are changing the same lines of the file, or for whatever reason the merge is more complicated than SVN can handle, it'll mark the file as conflicted and ask you to merge the conflicts manually (using a diff tool) when you try to update your local changes.

Basically, when you try to commit SVN will tell you that there are newer changes and you should update first. When you update it will conduct the merge on your local machine. Conflicted files will need to be fixed before you can commit. Once they're fixed and all changes merged, you can commit.

Upvotes: 6

Elad Lachmi
Elad Lachmi

Reputation: 10561

I think SVN will detect that the current file does not match the base version you were working with and ask you to do a manual merge.

Upvotes: 0

Piskvor left the building
Piskvor left the building

Reputation: 92752

The second person to commit the same file with the same revision will get a "SVN conflict" error, and it will be up to them to resolve it. See e.g. this: http://ariejan.net/2007/07/04/how-to-resolve-subversion-conflicts/

Upvotes: 2

Related Questions