# SVN workflow
- I recently found in a couple of latex projects on the svn server, where certain changes made by me were undone (overwritten) by earlier writeup. Please, if you haven't read the tutorial of svn, do read it and make sure that you understand what is conflicts. I want to show you two examples. First, is my daily routine of working on a project. The second one is what should you do if you run into a conflict (please don't do random actions when that happens to you. Like many other things, if you are not sure what to do, talk to your labmates, that's why you come to the lab. Or you can talk to me. Don't make random guess).
- Example 1: Today, I want to make another pass of MH's paper. So I swtich to the folder, and check if I have some local changes. THIS IS IMPORTANT BECAUSE OTHERWISE I WILL RUN INTO CONFLICTS ALMOST FOR SURE.
- This is what I see:
- bear@sslvpn-252-218 doc_apnoms19 % ***svn status***
```
M apnoms19.dvi
M apnoms19.log
M apnoms19.pdf
! apnoms19.synctex.gz
```
- You should have known what do the symbols mean. **M says I modified the file and ! says it's missing.**
- I modified the few binary files because I always recompile the pdf on my own computer before print the PDF for proofreading. I don't need the binary, and the easiest way to get rid of them is to delete these local files and do an svn update again.
- I use **make clean** in the shell prompt; you can use your mouse to delete them in the file manager (another reason you should abadon GUI and go with shell prompt. make clean takes me less than one second. Think about how many seconds it will take you to click through the 3 files and delete them).
- bear@sslvpn-252-218 doc_apnoms19 % ***make clean***
```
rm -f apnoms19.aux
rm -f apnoms19.dvi
rm -f apnoms19.log
rm -f apnoms19.tmp.pdf
rm -f apnoms19.pdf
rm -f apnoms19.bbl
rm -f apnoms19.blg
```
- bear@sslvpn-252-218 doc_apnoms19 % ***svn status***
```
! apnoms19.aux
! apnoms19.bbl
! apnoms19.blg
! apnoms19.dvi
! apnoms19.log
! apnoms19.pdf
! apnoms19.synctex.gz
```
- The new svn update shows I don't have a bunch of files, cuz I deleted them. But that's fine, cuz svn already saves the latest versions of these files (committed by MH a couple of weeks ago), so I just need to ask for the latest update.
- bear@sslvpn-252-218 doc_apnoms19 % svn update
```
Updating '.':
Restored 'apnoms19.log'
Restored 'apnoms19.dvi'
Restored 'apnoms19.aux'
Restored 'apnoms19.bbl'
Restored 'apnoms19.blg'
Restored 'apnoms19.pdf'
Restored 'apnoms19.synctex.gz'
U fig/DMP_diagram-eps-converted-to.pdf
U fig/IAP_diagram-eps-converted-to.pdf
A fig/error_flow_exec_ana.fig
A fig/error_flow_ia-eps-converted-to.pdf
U apnoms19.aux
U apnoms19.bbl
U apnoms19.blg
U apnoms19.dvi
U apnoms19.fdb_latexmk
U apnoms19.fls
U apnoms19.log
U apnoms19.pdfU dpm.tex
U iae.tex
U ref.bib
Updated to revision 506.
```
bear@sslvpn-252-218 doc_apnoms19 % svn status
- As you can see, I not only get back the missing file, svn also retrieves the new files written by MH. The last svn update shows that I have no local change <-- that's the starting point of my today's work, and you SHOULD do the same to avoid unnecessary conflicts. More symbols: **U means I got a newer version from the svn server, A means a new file.**
- ***Let me emphasize this again: make sure that you are aligned with the latest version before making any changes.***


- Now suppose I started proofreading the introduction.tex file. And I found a typo...BTW, **please, please, please install an in-editor spell-checker TODAY on all your EDITORS**. I use vim, and I only need to write an rc file to enable that. This is what I got. As you can see in < 1 ms, there is a highlighted word saying that I mispelt "police"
- So I fixed it by pressing "z="; your spell checker may work differently. Then I save the file and do an svn update again.
- bear@sslvpn-252-218 doc_apnoms19 % ***svn status***
```
M introduction.tex
```
- bear@sslvpn-252-218 doc_apnoms19 % ***svn diff introduction.tex ***
> Index: introduction.tex===================================================================--- introduction.tex (revision 506)+++ introduction.tex (working copy)@@ -5,7 +5,7 @@each surveillance camera produces a traffic stream at several Mbps. Fig.~\ref{fig:storage} illustrates a better way tomanage the video clips is storing them on the {\em storage server} in the {\em edge} network.The edge network interacts multiple nearby Internet-of-Things (IoT) devices, including surveillance cameras, and connects to the Internet via a {\em gateway} through an {\em access network.} Without uploading all the video clips to the cloud, the traffic load on the access network is reduced.-When users need to analyze the surveillance videos, they instruct nearby {\em analytics servers} to request corresponding video clips from the storage server. These analytics servers could be stationary servers installed in the edge network serving smartphone or laptop users; they could also be mobile servers installed on, for example, pilice cars. The sample video analytics include bus-stop passenger+When users need to analyze the surveillance videos, they instruct nearby {\em analytics servers} to request corresponding video clips from the storage server. These analytics servers could be stationary servers installed in the edge network serving smartphone or laptop users; they could also be mobile servers installed on, for example, police cars. The sample video analytics include bus-stop passengercounting, vehicles in pedestrian zones identification, and illegal parking detection.\begin{figure}[tbh]
- **You can see that introduction.tex is modified, marked as M**
- I also did a diff: you need to know how to use diff to compare two files...You can see one line is changed by me...(read the man page of diff if you haven't done that before)
- **Now, suppose I'm done today, I will commit the file. Before that I need to compile the PDF and check if everything looks fine. I do that by "make".**
- last few lines of the output of make (which consists of ~ 5 steps)... (see the transcript file for additional information)Output written on apnoms19.dvi (11 pages, 92688 bytes).Transcript written on apnoms19.log.# apnoms19.pdf: apnoms19.dvidvipdfm apnoms19.dviapnoms19.dvi -> apnoms19.pdf[1][2][3][4][5][6][7][8][9][10][11]1715338 bytes written# dvipdfm apnoms19.dvi apnoms19.tmp.pdf# gs -sDEVICE=pdfwrite -q -dBATCH -dNOPAUSE -dSAFER -dPDFX -dPDFSETTINGS=/prepress -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -sOutputFile=apnoms19.pdf -c '<</NeverEmbed []>> setdistillerparams' -f apnoms19.tmp.pdf -c quit # rm -f apnoms19.tmp.pdf
- **I visually check the pdf, and do an svn update again**
- bear@sslvpn-252-218 doc_apnoms19 % ***svn status***
```
M apnoms19.dvi
M apnoms19.log
M apnoms19.pdf
! apnoms19.synctex.gz
M introduction.tex
```
- Now you see that some binary files were changed, because I just recompiled them.
- **Suppose I want to commit. There are two ways of doing that: (a) I commit everything including binary. I would recommend this if you are the only one who is editing all the tex files (we sometimes says you get the token); or (b) I only commit the source files, in this case, introduction.text. The difference is to avoid conflicts in binary files.**
:::info
Suppose I want to do (a):
what I will do is:
**(1) svn update, to get the synctex.gz, also make sure that there is no conflict if I commit now. You want to resolve the conflicts before trying to commit.
(2) svn status, check again if everything is either M or A, if you get a C (conflict) fix it, before moving ahead.
(3) svn commit -m "your checkin note" .**
:::
- bear@sslvpn-252-218 doc_apnoms19 % svn update; svn status; svn commit -m "demo A for how to use svn" .
```
Updating '.':
At revision 506.
M apnoms19.dvi
M apnoms19.log
M apnoms19.pdf
M introduction.tex
Sending apnoms19.dvi
Sending apnoms19.log
Sending apnoms19.pdf
Sending introduction.tex
Transmitting file data ....done
Committing transaction...
Committed revision 507.
```
- Then I'm done with today's work....I want to check if I overlooked any files. So I will do this one last time:
- bear@sslvpn-252-218 doc_apnoms19 % ***svn update; svn status***
```
Updating '.':
At revision 507.
```
- **Many of you don't do the last steps, and that's why new (especially) figures are often left out from your check-in, and I had to ask you to add them again. If you do svn status often enough, from the top level of the paper folder, you should see ? in front of your newly added files.**
- That's my and should be your daily life. If you follow the above steps and properly communite with your team-member (we work in a small group, that's why token system works), then you should never run into conflict. I guess I will stop here, and show you how to avoid conflicts in the next group meeting, if any of you wants to know (please remind me).
- Maybe you are thinking your future jobs will not use svn; but all version control systems are built upon the same unix tools, like diff. Their behaviors when running into conflicts are very similar....So, please don't skip my explanations above.
- Take aways: (1) create your own working pattern similar to what I show you to avoid conflicts, (2) always commit your changes asap, let tools help you to avoid conflict when it's not too late, and (3) install spell checkers in all your editors.