Thursday, June 23, 2011

Handling Conflicts while Merging in Subversion

Conflicts occur when Subversion is unable to merge two files together automatically. Generally, this happens when two users have independently made a change to the same area of a file. Because Subversion doesn’t actually understand the files that it merges, it has no way of figuring out which of the two versions to use. Its only recourse, in this case, is to let the user solve the conflict.

Before you can resolve a conflict, you have to have a conflict. So, let’s create a conflict. To start, check out a new working copy, which will represent the work of a second developer.

$ svn checkout file:///home/bill/my_repository/trunk/ /home/bill/ ¬
A other_dev_trunk/hello.c
A other_dev_trunk/Makefile
Checked out revision 7.

Then, edit the file hello.c in your new working copy, and change the line

printf{"Subversion Rocks!!\n");

so that it reads

printf("Subversion is Great!!\n");

After the change has been made, commit it to the repository

$ svn commit --message "Changed to a more conservative phrase" /home/ ¬
Sending hello.c
Transmitting file data .
Committed revision 8.

With your changes from the new working copy committed, it’s time to go back to your original working copy. Once there, edit the copy of the file hello.c that is stored there, without updating the file from the repository first. This time, change the line

printf("Subversion Rocks!!\n");

to the third, yet equally complimentary line,

printf("Subversion is Awesome!!\n");

Now, try to commit this change to hello.c.

$ svn commit --message "Decided on a more hip phrase" /home/bill/ ¬
Sending my_repos/trunk/hello.c
svn: Commit failed (details follow):
svn: Out of date: '/my_repos_trunk/hello.c' in transaction '9'

No comments:

Post a Comment