noresm:svntutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
noresm:svntutorial [2013-12-10 13:48:49]
alfg [SVN TUTORIAL BRANCH/MERGE TUTORIAL]
noresm:svntutorial [2022-05-31 09:29:32] (current)
Line 53: Line 53:
 </file> </file>
  
-==> YOU NOW HAVE A REPOSITORY CONTAINING TRUNK AND (EMPTY) BRANCHES DIRECTORY. YOU CAN START TO USE IT+==>YOU NOW HAVE A REPOSITORY CONTAINING TRUNK AND (EMPTY) BRANCHES DIRECTORY. YOU CAN START TO USE IT
  
-===== PART 2: CREATE A DIRECTORY FOR TWO DEVELOPERS (one working on trunk and other on branch+===== PART 2: Create a working directory for two developers ==== 
-BOTH DEVELOPERS SHOULD BE CONNECTED TO THE SVN REPOSITORY ====+ 
 +<file> 
 +alfg@pc4400:~$mkdir twoDevelopers 
 +alfg@pc4400:~$cd twoDevelopers 
 +</file> 
 + 
 +CHECK OUT TRUNK FOR ONE DEVELOPER 
 +<file> 
 +alfg@pc4400:~/twoDevelopers$svn checkout file://$HOME/svnrepos/testproject/trunk trunk 
 +alfg@pc4400:~/twoDevelopers$cd trunk 
 +</file> 
 + 
 +CREATE A BRANCH BASED ON TRUNK 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/trunk$ svn copy file://$HOME/svnrepos/testproject/trunk file://$HOME/svnrepos/testproject/branches/aBranch -m "created branch aBranch" 
 +</file> 
 + 
 +CD BACK ONE STEP AND CHECK OUT THE BRANCH FOR THE OTHER DEVELOPER 
 +<file> 
 +alfg@pc4400:~/twoDevelopers$ svn checkout file://$HOME/svnrepos/testproject/branches/aBranch aBranch 
 +</file> 
 + 
 + 
 +==> THE DIRECTORY "TWODEVELOPERS" NOW HAS TWO DIRECTORIES, ONE WITH TRUNK AND ONE WITH A BRANCH VERIFY THAT THEY ARE THERE 
 +USING THE "LS" COMMAND 
 + 
 +<file> 
 +alfg@pc4400:~/twoDevelopers$ ls -trl 
 +total 8 
 +drwxrwxr-x 3 alfg alfg 4096 Dec  9 08:36 trunk 
 +drwxrwxr-x 3 alfg alfg 4096 Dec  9 09:40 aBranch 
 +</file> 
 + 
 + 
 +=====PART 3: Create conflict in the file test.F90 ===== 
 + 
 +EDIT FILE ON TRUNK 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/trunk$ vim test.F90  
 +alfg@pc4400:~/twoDevelopers/trunk$ svn commit -m "added hello" 
 +alfg@pc4400:~/twoDevelopers/trunk$ svn update 
 +</file> 
 + 
 +EDIT FILE ON BRANCH 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ vim test.F90  
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn commit -m "added Hi man" 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn update 
 +</file> 
 + 
 +==> We have now created a conflict between the branch "aBranch" and "trunk" 
 + 
 +<file> 
 +alfg@pc4400:~/twoDevelopers$ diff aBranch/test.F90 trunk/test.F90  
 +9c9 
 +< print*, "Hi Man! a+b is " , a+b 
 +--- 
 +> print*, "Hello a+b is " , a+b 
 +</file> 
 + 
 +===== PART 4: Test the merge dialog ===== 
 + 
 +TRY TO MERGE TRUNK INTO BRANCH 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn merge file://$HOME/svnrepos/testproject/trunk 
 +</file> 
 + 
 +You will get the message that there is a conflict in file test.F90, you will have to resolve the conflict 
 +Push the "postpone" option to quit the merge dialog 
 + 
 +UNDO THE MERGE WITH  
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn revert -R . 
 +</file> 
 + 
 +==> You have undone the merge, nothing has happened 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn diff 
 +alfg@pc4400:~/twoDevelopers/aBranch$ 
 +</file> 
 + 
 +===== PART 5: Set up favourite editor as merge tool ===== 
 + 
 +1) Create a file somewhere in your pc, for example I use 
 +$HOME/bin/mergetoolscript.sh 
 + 
 +For emacs users, the content of the script is:  
 + 
 +<file> 
 +#!/bin/sh 
 +emacs -q --eval "(ediff-merge-files-with-ancestor "\"$2"\" \""$3"\" \""$1"\" nil \""$4"\")" 
 +</file> 
 + 
 +For vi users, the content of the script is:  
 + 
 +<file> 
 +#!/bin/sh 
 +vim -d "+diffsplit $3" "+vert diffsplit $1" "+vert diffsplit $2" -o $4 
 +</file> 
 + 
 +2) Open your $HOME/.subversion/config file and replace the line with merge tool (NOTE THAT FULL PATH IS NEEDED. NO BLANK CHARACTERS AT BEGINNGING OF LINE!!) 
 +<file> 
 +merge-tool-cmd = /home/alfg/bin/mergetoolscript.sh  
 +</file> 
 + 
 + 
 +MAKE SURE SCRIPT IS EXECUTABLE 
 +<file> 
 +chmod +x $HOME/bin/mergetoolscript.sh 
 +</file> 
 + 
 +==> You should now have working merge tools. This will make merging EASY!! 
 + 
 + 
 +=====PART 6: Go back to merge operation and use merge tool ===== 
 + 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn merge file://$HOME/svnrepos/testproject/trunk 
 +</file> 
 + 
 +type "s" to "show all options" and "l" to "launch external tool".  
 + 
 +==> emacs or vi should be invoked in "merge mode" 
 + 
 +//The vi script// shows (your, ancestor, mine) on top and output below. Move around in the different windows with "ctrl+w+arrow". When in the upper windows you can use "[c" and "]p"] go move to previous/next diffs. 
 + 
 +//the emacs script// shows (yours, mineon top and merged version (including common ancestor) below 
 + 
 +All editing should happen in the lowest part of the editor window 
 + 
 +When done editing, save the file and quit the editor 
 + 
 +When back in the merge-dialog, press "r" (resolved) 
 + 
 + 
 +===== PART 7: Verify that you are happy with merge ===== 
 + 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn diff 
 +</file> 
 + 
 +Note how it is difficult to understand the diff ==> we need to configure a diff tool! 
 + 
 +To configure a nice diff-viewer, you need to replace a line in your $HOME/.subversion/config file like this:   
 + 
 +<file> 
 +diff-cmd = /home/alfg/bin/diffwrap.sh  
 +</file> 
 + 
 +The script "diffwrap.sh" has be created somewhere on your PC. The script is only TWO LINES long!! (Make sure it is executable with "chmod +x scriptname"
 + 
 +The content of this script (only two lines) for emacs users can be:  
 + 
 +<file> 
 +#!/bin/sh 
 +emacs --eval "(ediff-files "\"$6"\" \""$7"\" )" 
 +</file> 
 + 
 +(In emacs, use | (pipeline) key in the "ediff" dialog to toggle between vertical/horizontal diff view) 
 + 
 +The content of this script for vi users can be 
 + 
 +<file> 
 +#!/bin/sh 
 +vimdiff $6 $7 
 +</file> 
 + 
 +Visually verify the diff again using the diff viewer 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn diff 
 +</file> 
 + 
 +When you are happy with the diffs, do  
 + 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/aBranch$ svn commit -m "Successfully branched trunk to my branch" 
 +</file> 
 + 
 +==> DONE 
 + 
 +===== PART 8: Merge back to trunk ===== 
 + 
 +After the conflict is resolved and committed from branch, go back to trunk 
 + 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/trunk$ svn update 
 +alfg@pc4400:~/twoDevelopers/trunk$ svn merge --reintegrate file://$HOME/svnrepos/testproject/branches/aBranch 
 +</file> 
 + 
 +AT THIS POINT YOU WANT TO PASS THE TESTS (IF THIS WAS NORESM) 
 + 
 +<file> 
 +alfg@pc4400:~/twoDevelopers/trunk$ svn commit -m "merged aBranch back to trunk" 
 +</file> 
 + 
 +==> Observe that you don't get any conflict this time. Svn knows that the conflict is already resolved. 
 + 
 + 
 +===== Other important points ===== 
 + 
 +  * The merge is not completed until you commit! 
 +  * You have to know if you are doing a reintegrate merge or a merge from trunk (see noresm wiki) 
 +  * You can undo the merge with alfg@pc4400:~/twoDevelopers/aBranch$ svn revert -R . 
 +  * When you have done a "reintegrate merge", consider  your branch dead! (svn delete branchUrl -m "removed reintegrated branch aBranch"
 +  * If you insist on keeping reintegrated branches alive, there are two options: 
 +      - Start using another version control system 
 +      - Make sure you have latest svn version (version >= 1.7), Then read (and understand)  http://svnbook.red-bean.com/en/1.7/svn.branchmerge.advanced.html#svn.branchmerge.advanced.reintegratetwice 
 +  
  • noresm/svntutorial.1386683329.txt.gz
  • Last modified: 2022-05-31 09:23:24
  • (external edit)