Archive for September, 2010

SVN – Quick Startup

Friday, September 10th, 2010

SVN (or Subversion) Quick Startup

For version control – In 3 to 4 easy steps, place a given directory and all dirs and files under that directory, under SVN control.

Process Summary – Create a Repository, Import current files into that repository, Checkout files from repository to desired working directory, work on files, committing as you go to collect versioning information.

  1. Create a repository
    • i.e. svnadmin create –fs-type fsfs /path/to/svnrepo
  2. Import files into the repository
    • i.e. svn import /path/to/files/you/want/under/svn-control/ file:///path/to/svnrepo/ -m “Initial import”
    • NOTE; This will import all sub-dirs as well.
  3. Probably delete the original location of the files imported into the repo, backing up the originals first of course.
    • i.e. rm -rf /path/to/files/you/want/under/svn-control/
    • NOTE; Of course, this isn’t relevant if your going to place working copy somewhere other than original location.
  4. Create a working copy/location where you want the files to reside.
    • i.e svn checkout file:///path/to/svnrepo/ /path/to/final/working/location/
  5. Work on files in /path/to/final/working/location/.
    • i.e. cd /path/to/final/working/location/; vi <somefile>; svn diff; svn commit -m “First edits”
    • NOTE: All subdirs are under SVN as well. Commands like “svn commit” will propagate to subdirs as well.
  6. A specific example; putting my ~/bin/ directory under SVN control.
    • $ svnadmin create –fs-type fsfs ~/MyBinDirSVNRepo/ # create repo
    • $ svn import ~/bin/ file:///home/bryan/MyBinDirSVNRepo/ -m “Initial bindir Import” # import files into repo
    • $ tar -cvf ~/bin.tar ~/bin/ # backup original files
    • $ gzip ~/bin.tar
    • $ rm -rf ~/bin/ # remove original files
    • $ svn checkout file:///home/bryan/MyBinDirSVNRepo/ ~/bin/ # checkout files back into orig location
    • Now all files under ~/bin/ are under SVN control. # Edit and commit

Cheatsheet:

  • svn diff ; see what’s different before commiting.
  • svn diff -r 1:2 <somefile> ; show diff between ver 1 and ver 2 of <somefile>
  • svn diff -r 5 <somefile> ; show diff between current working copy and ver 5.
  • svn commit ; if you leave off the “-m” you’ll be prompted to enter a comment.
  • svn blame <somefile> ; see who edited each version (blame being mis-leading of course)
  • svn info ; repo info, like were the repo is located.
  • svn info <somefile> ; everything you wanted to know about a file in the repo, latest ver, etc, etc.
  • svn info <somefile> ; everything you wanted to know about a file in the repo, latest ver, etc, etc.
  • svn list ; everything in the repo
  • svn ls ; same as “svn list”
  • svn status -v ; provides latest version of each file. Useful in know were to start doing “svn diff -r #:# <somename>
  • svn add <newfile> ; adding a new file to the repo.
  • svn status ; show status of each file (if all matches repo, then no output)
  • svn update ; syncs with repo, includes pulling in diffs in repo into working copy. Only makes sense if you have multiple copies checked out.

References: