16
Tutorial Contents: # Subversion Introduction # Subversion Commands # Subversion content properties # Subversion and Graphical diffs # Subversion GUI interface # Subversion Security Tips # Subversion utility commands and scripts # Subversion Best Practices # Tips # Links # Books rev 401 rev 402 rev 403 search Search | Home Page | Linux Tutorials | Terms | Privacy Policy | Advertising | Contact | Related YoLinux Tutorials: °Subversion Server and Trac Server Installation and Configuration °Subversion Repository Transfer °RabbitVCS client °Jenkins Automated Builds and Subversion °Cabie Automated Builds and Subversion °Software development tools °Clearcase Commands °Clearcase Client Install °Clearcase Server Install °Subversion vs Clearcase °CVS Intro °RCS Intro °C++ Info, links Subversion Introduction: Subversion is a software source code "Change Management" (CM) system for collaborative development. It maintains a history of file and directory versions. The files and directories are checked out of the repository and into your local project work area. This called your "working directory". Changes are made to files in your "working directory". After changes are made to the create the next working version, the files are checked into the Subversion CM repository. Subversion Commands: Subversion command summary cheat sheet: Command Description svn --help List Subversion commands svn help command Also: ? or h Help on given "command" svn add filename svn add directory Add a file or directory to Subversion CM control. Must also perform: svn ci filename (or svn commit ) to upload the file or directory. File will not be available in the repository until a "commit" is performed. If adding a directory, the directory and all of its contents recursively are added. i.e.: svn ci directory svn commit directory svn commit . svn blame filename svn blame -r RevisionNumber filename Also: praise, annotate, ann Show file contents with revisions annotated with author information. svn cat filename List contents of file under Subversion control.

Subversion Commands and Scripts

Embed Size (px)

DESCRIPTION

Subversion

Citation preview

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 1/16

    Subversion Commands andScripts

    Subversion (SVN) command summary cheat sheet, use, best practices, tipsand scripts. This tutorial covers version control with Subversion using thecommand line interface, GUI clients and scripts which interface Subversion with GUI diff tools.

    Tutorial Contents:

    # Subversion Introduction# Subversion Commands# Subversion content properties# Subversion and Graphical diffs# Subversion GUI interface# Subversion Security Tips# Subversion utility commands and scripts# Subversion Best Practices# Tips# Links# Books

    rev 401 rev 402 rev 403

    search Search | Home Page | Linux Tutorials | Terms | Privacy Policy | Advertising | Contact |

    Related YoLinuxTutorials:

    Subversion Server and TracServer Installation andConfiguration

    Subversion RepositoryTransfer

    RabbitVCS client

    Jenkins Automated Buildsand Subversion

    Cabie Automated Buildsand Subversion

    Software developmenttools

    Clearcase Commands

    Clearcase Client Install

    Clearcase Server Install

    Subversion vs Clearcase

    CVS Intro

    RCS Intro

    C++ Info, links

    Subversion Introduction:

    Subversion is a software source code "Change Management" (CM) system for collaborative development.It maintains a history of file and directory versions. The files and directories are checked out of therepository and into your local project work area. This called your "working directory". Changes are made tofiles in your "working directory". After changes are made to the create the next working version, the files arechecked into the Subversion CM repository.

    Subversion Commands:Subversion command summary cheat sheet:

    Command Description

    svn --help List Subversion commands

    svn help commandAlso: ? or h

    Help on given "command"

    svn add filename

    svn add directory

    Add a file or directory to Subversion CM control. Must also perform: svn ci filename (or svncommit) to upload the file or directory. File will not beavailable in the repository until a "commit" isperformed. If adding a directory, the directory and allof its contents recursively are added. i.e.:svn ci directory

    svn commit directorysvn commit .

    svn blame filename

    svn blame -r RevisionNumber filename

    Also: praise, annotate, ann

    Show file contents with revisions annotated withauthor information.

    svn cat filename List contents of file under Subversion control.

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 2/16

    Java on Linux

    YoLinux Tutorials Index

    Free InformationTechnology Magazinesand DocumentDownloads

    Free InformationTechnology Software

    and Development

    MagazineSubscriptions andDocument Downloads

    svn checkout http://node-

    name/repos/svn/trunk/parentPath/path

    This creates:path/file1path/file2...

    svn checkout http://node-

    name/repos/svn/trunk/parentPath .

    This creates:path/file1path/file2...Note the difference a "." makes.

    svn checkout file:///repos/svn/trunk/path/

    svn co -r 497 http://node-

    name/repos/svn/trunk/path file-name

    Also: svn co https://..., svn://..., andsvn+ssh://

    MS/Windows: svn cofile:///c:/repository/project/trunk

    Checkout every file from the path and subdirectoriesspecified below. Creates "working" copy of files anddirectories.Checkout a repository.

    Use option "-r" to specify a specific revision otherthan the latest.

    The URL "svn://" communicates with an SVN server(port 3690)

    The URL "http://" comunicates with the Apacheserver and module mod_dav_svn (port 80) [morecommon server]

    svn cleanup Cleanup subversion files resulting from escapedprocesses and crashed.

    svn commit filenamesvn commit --message "Message goes here."

    filename

    svn commit -m "Message goes here." filename

    svn ci filename1 filename2 filename3svn ci .

    Check-in (commit) local "working" file, files ordirectory and contents (recursively) into Subversionrepository. Atomic, i.e. all committed or none, noincomplete check-in.

    svn copy source destination_clone

    Also: svn cp ...Copy file or directory tree. One can copy from onelocal working copy to another or to repository serverURL's. The sources and destinations can beworking copies or URLs.

    svn copy http://host/repos/project/trunk

    http://host/repos/project/tags/TagName-1.4.5-m "Tag Release 1.4.5"

    Tag a release. Takes a snapshot of the repositoryand assigns a name. This can be performed at anydirectory branch.

    svn copy .

    http://host/repos/project/tags/TagName-1.4.5-m "Tag Release 1.4.5"

    Tag a release. Takes a snapshot of your localworking copy and assigns a name. This can beperformed at any directory branch.

    svn delete filename

    svn delete directory

    Also: del, remove or rmsvn rm http://host/repos/project/trunk/file-

    or-directory

    Delete file from repository. The UNIX command rmfile-name. Must perform a "commit" to update therepository and local working directory with thechanges. i.e.: svn commit .

    svn diff filename

    svn di filenameShow file diffs between SVN repository and your filechanges using GNU file diff format. Use GUI difftools as shown below.

    svn diff -r rev1:rev2 filename Show file diffs between specified versions.Example: svn diff -r 456:459 subfn.cppUsing GUI diff tool: svn diff -r 457:459 --diff-cmd kdiff3 file-name

    svn diff filename > patch-file Generate patch file used by the patch command.

    svn export directory Export directory tree to your file system but it will notbe a "working directory" under SVN control.

    svn export -r Rev-Number http://node-

    name/pathExport directory tree of specified version and createlocal directory tree and files not under SVN control.

    svn import local-directory

    http://node/repos/svn/trunk/directoryAdd directory (and files in it recursively) to path inrepository specified.

    svn info filename Display information about file or directory. (Datemodified, author, revision, path in repository.)Can not specify a URL.

    svn list directory List file or directory of files in repository. Used to

    Linux Commands

    Subversion

    SVN Repository

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 3/16

    18

    Advertisements

    HTML Editor

    HTML 4.0

    Free PHP

    Tutorial

    Definition Of

    HTML

    Learning

    HTML Code

    HTML Class

    HTML

    Language

    HTML Source

    Code

    HTML Tutorial

    ads

    svn list file-name browse repository before checkout. If currentdirectory is given (svn list ./), then Subversionwill list the repository URL of the current directory.

    svn list -r RevisionNumber directory List directory of files in repository in specifiedrevision.

    svn lock filename -m "comment as to why its

    locked or by whom"

    (Comment is not required but is oftenuseful)

    Lock file to grant exclusive access to one and forbidall others. A commit will unlock the file (unless the "--no-unlock" option is used). A lock can be removedwith the commands: svn unlock filename, svnlookand the svnadmin comands (i.e. List: svnadminlslocks and remove: svnadmin rmlocks filename).

    svn log filenamesvn log .

    svn log http://URL/path/filesvn log -v .

    svn log -r RevisionNumber

    http://URL/path/file

    Show the Subversion log messages for a set ofrevision(s) and/or file(s) and/or all directory contentsin repository. List verbose. Includes list of all files in changeShows the file changes associated with revisionnumber.

    svn merge http://url/path/branch1

    http://url/path/branch2 working-local-dir

    svn merge file1@revJ file2@revK

    svn merge -r 414:411 http://url/path

    working-dir

    svn merge -r 413:HEAD file-name

    Merge directory changes into your current workingdirectory or merge a file in Subversion into the file inyour working directory. If target is not specified, theidentical basename or current directory is assumed.Used to incorporate changes checked in which arenot accounted for in your file or to merge branches.Example using GUI merge tool: svn diff -r 459:454 --diff-cmd kdiff3 --

    extensions '-m' file-name Next, tell subversion that the conflicts have beenresolved: svn resolve file-name

    Finally, check-in file: svn ci file-name or abort changes: svn revert file-name

    svn merge --dry-run -r 414:413

    http://url/pathTest merge. No changes are made to your localworking copy but shows Subversion feedback as ifmerge was performed.

    svn merge -r 414:413 http://url/pathsvn merge -r 414:413 .

    Undo changes committed in revision 414.

    svn mkdir directory

    svn mkdir http://URL/directoryCreate a new directory under version control.

    svn move directory1 directory2

    svn mv directory1 directory2

    svn mv file-old-name file-new-name

    Rename or move a file or directory. Moves/renamesfile/directory in repository and in local work area.Must perform svn ci file-new-name after the movefor changes to to take place in repository.

    svn revert filename Undo changes in local work files. Throw away localchanges.

    svn resolved filename Run this command after resolving merge conflicts.Next "commit" your changes.

    svn statussvn status -usvn status -u .svn status -uq .

    Show status of file changes in current directory andrecursively in directories below.Show out of date file info: svn status --show-updates

    (equivalent: svn status -u) -u: Determines status by comparing your localrepository with the server repository. Without thisoption, the status shown will only be the changes youhave made in your local repository.

    -q: Quiet. Do not print "?: File/directory not underversion control" or "!: File/directory missing"extraneous information.

    First collumn:

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 4/16

    SteelSeries

    Zboard Gaming

    Keyboard

    SteelSeries

    New $23.99

    D-Link DI-514

    Wireless

    Cable/DSL Rou...

    D-Link

    New $59.99

    IOGEAR

    GUC1284B USB

    to Parallel Adap...

    IOGEAR

    New $22.57

    D-Link DI-604

    Cable/DSL

    Router, 4-Po...

    D-Link

    New $29.95

    Sonnet

    Technologies

    TSATA SATA PCI

    A...

    SONNET

    TECHNOLOGIE...

    New $60.24D-Link DGE-530T

    10/100/1000

    Gigabit ...

    D-Link Systems,

    In...

    New $21.45

    Privacy Information

    Jobs

    Softw are/DevOps

    Engineer

    New York, NY

    Sharew ave

    SDE2 Lead-STBC-Beijing

    Beijing, Beijing, China

    Microsoft

    Need PHP Programmer

    for Emerging...

    Kansas City, KS

    Rx Savings Solutions

    Window s System

    Administrator

    Carrollton, TX

    MCG - Midw est

    Consulting Group

    Linux Expert

    Hannver,

    Niedersachsen,

    Germany

    Jet Consulting

    Java Developer - QNX

    and UNIX -...

    Frankfurt am Main,

    Hessen, Germany

    Optimus Search Limited

    CAS Softw are

    Consultant

    Atlanta, GA

    Request Technology-

    Anthony Honquest

    Senior Technical

    A: File to be addedC: Conflicting changesD: File to be deletedG: File to be merged with updates from serverM: File has been modifiedR: File to be replacedG: File to be mergedX: Resource is external to repository(svn:externals)?: File/directory not under version control!: File/directory missing~: Versioned item obstructed by some item ofa different kind.

    Second collumn: Modification of properties

    ' ' no modifications. Working copy is up todate.'C' Conflicted'M' Modified'*' Local file different than repository. A newerrevision exists on the server. Update will resultin merge or possible conflict.Third collumn: Locks

    ' ' not locked'L' locked'S' switched to a branch

    svn switch http://server/new-branch

    svn switch --relocate http://server/old-path

    http://server/new-path

    Switch your local working copy to mirror a newrepository branch instead of main trunk or previousbranch. Also allows you to point your repository to anew path on the server if the server path changessince you performed a check-out.

    svn update

    svn update filename

    svn update -r458 filenamesvn update --ignore-externals ./

    Migrate all updates from Subversion repository toyour local copy (recusively for all files in the currentdirectory and all below it). If there have beenupdates to the svn repository since you downloadedthe files, subversion will give you the opportunity tomerge. Status of files will use the coding as statedabove for "status". Files marked with a "C" (conflict)should be merged of reverted. If merged then onecan perform a "resolve" and then a "check-in".If a file name is specified, only that file is updated. Can also syncronize to a specified revision given by-r.Use --ignore-externals to avoid the slow processingof externals to a potentially slow distant internetserver.

    Where RevisionNumber is:

    HEAD: The latest revision in the repository.BASE: The "pristine" revision of an item in a working copy. Matches checked out version before anymodifications.COMMITTED: The last revision in which an item changed before (or at) BASE.PREV: The revision just before the last revision in which an item changed. (Technically, COMMITTED- 1.)

    Example Session:

    (Assumes that the repository has already been created. For Subversion repository creation andSubversion server configuration, see the (YoLinux Subversion and Trac tutorial)

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 5/16

    Support Application...

    Chicago, IL

    Request Technology-

    Robyn Honquest

    Cloud Customer

    Success Technologist

    Bangalore, Karnataka,

    India

    Informatica

    SAP Solution Manager

    Spezialist (m/w )

    Walldorf, Baden-

    Wrttemberg, Germany

    emagine

    POST A JOB >

    POWERED BY JOBTHREAD

    Checkout: svn checkout http://svnserver/repos/svn/trunk/Project1Go to source code directory: cd Project1/srcEdit files:

    vi file1.cpp

    vi file2.cpp

    Verify and test: make We are ready to check-in the files into the Subversion repository.Check repository and report on new revisions and changes others have checked in: svn status -u.

    After many long hours or days of editing and work, get updates others have made: svn update

    U file.h C file1.cpp G file2.cpp ? a.out

    You will see:U: File was updated with a newer version checked-in since your checkout.G: Automatically merged with no conflicts.C: Not merged due to conflicts. You made changes to the same section of code as the updatemade by someone else since your checkout.

    For each "conflicted" file there will be three new local files generated by "update":file1.cpp.mine (File - post editing)file1.cpp.rold (BASE - pre editing)file1.cpp.rnew (HEAD - Updated file from repository)

    The file file1.cpp still exists but with svn conflict marker strings added in the file. At this point, a check-in will fail until the merge is resolved.Merge options:

    Edit the file file1.cpp Text markers are placed in the file to show the conflicts between the "HEAD" and "mine"versions. ORtkdiff -conflict file1.cpp ORUse a GUI merge tool: kdiff3 file1.cpp.mine file1.cpp.rnew -o file1.cpp ORThrow out your changes/abort: svn revert file1.cpp No resolve or check-in necessary if file is reverted.

    Verify and test, again: makeNotify Subversion that conflicts have been resolved: svn resolved file1.cpp Note: This also removes the temporary files ".mine" and ".r###".Check-in to Subversion repository: svn ci -m "Add comments here" file1.cpp

    Subversion Peg revisions:

    Peg revisions are used so Subversion can find a previous version of a resource (file or directory) if its'location was different than it is now. Peg revisions are that extra hint Subversion needs to clear upambiguity.

    $ svn command -r OPERATIVE-REV item@PEG-REV

    The default peg revision is BASE for working copy items and HEAD for repository URLs. When nooperative revision is provided, it defaults to being the same revision as the peg revision.

    The PEG-REV is specified if the resource (file/directory) in question use to appear in a directory which isno longer in the same place or no longer exists. The "peg-revision" must be specified so subversion canlook at the directory in that revision so it can find the resource.

    If a peg revision is specified without an operative revision, then the operative revision is assumed to be thesame as the peg revision.

    For more see: http://svnbook.red-bean.com/en/1.5/svn.advanced.pegrevs.html

    Subversion Properties:

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 6/16

    Files under revision control can include Subversion keywords which properties can be set with the"propset" command. Keywords are substituted with the Subversion properties and will not appear in the fileuntil a commit is performed. Other properties are used to modify the behavior of Subversion.

    The following properties can be set on entities stored in Subversion:

    Property Description

    svn:ignore A newline separated list of file patterns to ignore. List of files/directories to be ignored bysvn status

    svn:keywords Valid RCS style keywords are:

    HeadURL - The URL for the head version of the object. Also: $URL$LastChangedBy - The last person to modify the file. Also: $Author$

    LastChangedDate - The date/time the object was last modified. Will appear as: $LastChangedDate: 2005-07-22 22:02:37 -0700 (Fri, 22 Jul2005) $ Also: $Date$LastChangedRevision - Describes the last known revision. Will appear as: $LastChangedRevision: XXX $ where "XXX" is the revisionnumber. Also: $Rev$, Revision$Id$ - A compressed summary of the previous 4 keywords.

    Example RCS stylecomment

    Example Output

    /* $URL$ $Rev$ $Author$ $Date$ $Id$ */

    /* $URL:http://server/svn/path/file.cpp $ $ Rev:2 $ $ Author:Greg $ $ Date:2006-10-12 14:31:84 -0400 (Thu,12 Oct 2006)$ $ Id:file.cpp 3 2006-10-12 18:31:84Z Greg $ */

    To turn on keyword processing for $URL$ and $Rev$ set the property svn:keywords andcommit the file. The property is not assigned until a commit is performed. Subsequentcheck-outs and updates will have substitution performed on the working file:

    svn propset svn:keywords "URL Rev" source-file.cpp

    To turn this substitution off so that one can edit the original keywords. This also requires acheck-in:

    svn propdel svn:keywords source-file.cpp

    svn:executable Ensure file attribute is executable. Possible values: ON, OFFExample: svn propset svn:executable ON app.exe

    svn:eol-style One of 'native', 'LF', 'CR', 'CRLF'. Specify and maintain specified line ending for text file.

    LF: Unix, Linux, standards based OS, proprietary legacy systems, etc.CRLF: DOS and Microsoft OSsCR: Response input scripts, etc

    Example: find ./ -name "*.h" -exec svn propset svn:eol-style LF {} \;

    svn:mime-type The mime type of the file:

    text/html

    text/css

    text/plain

    image/jpeg

    ...

    See file /etc/mime.types for a list of mime types.

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 7/16

    Examples:

    svn propset svn:mime-type text/plain file.cpp

    svn propset svn:mime-type text/html file.html Web pages rendered from subversion will display as HTML source rather than as aweb page unless this mime type is applied.

    svn:needs-lock

    Prevents conflicts for files which can not be contextually merged. i.e. photos, binaries,object libraries.

    svn:externals List of files or directories pointed to. Locate repository where directory specified shouldbe retrieved. The directive propset is not required:

    svn propedit svn:externals local-target-dir

    local-target-dir http://server/svn/dir-remote

    local-target-dir/subdir -r### http://server/svn/dir-remote2

    svn updatesvn commitsvn propget svn:externals ./

    The property applies to the directory. Subversion can not list or web browse svn:externals.Check-out ("co"), "export" and "log" can be performed. Must set environment variable "EDITOR", "SVN_EDITOR", "VISUAL" or set theSubversion configuration file (~/.subversion/config) attribute editor-cmd. i.e.: exportEDITOR=vi

    Note: Subversion 1.6 introduces file externals in addition to directory externals. The fileshowever must reside in the same repository. Also, the file must point to a location whichexists in your local working directory.

    [Potential Pitfall]: Apply svn externals to directories and not files. (version 1.4)

    [Potential Pitfall]: If generating a tag (branch), one should assign the revision number tothe external link to truly snapshot the repository for that tag. This revision number shouldbe specified in the tagged branch version of the svn external.

    [Potential Pitfall]: The revision numbers shown by svn info will reflect the versionnumbers of the repository in which the files are stored. If the files are imported via an svnexternal directory, the revision numbers will reflect that of the external repository which theexternal points to and thus from where the files were imported.

    Command Description

    svn propdel PropertyName file-name

    svn propdel --revprop -r RevisionName

    http://url/path

    Also: pdel, pd

    Remove property name from files or directories.Remove properties on file in repository.

    svn propedit PropertyName file-name

    svn propedit --revprop -r RevisionName

    http://url/path

    Also: pedit, pe

    Edit property name of files or directories.Edit properties on file in repository.

    svn propget PropertyName file-name

    svn propget --revprop -r RevisionName

    http://url/path

    Also: pget, pg

    Print value of property name of files or directories.Print properties on file in repository.

    svn proplist file-namesvn proplist *

    svn proplist --revprop -r RevisionName

    http://url/path

    Also: plist, pl

    List properties of file, files or directory.

    svn propset PROPNAME PropertyValue file-

    namesvn propset PROPNAME --revprop -r

    RevisionName PropertyValue http://url/path

    svn propset svn:mime-type text/html file-

    Set properties of file or directory.Set mime type for a file in the repository. Must performa commit to upload changes to the repository.

    Set file properties so that "^M"'s are removed upon

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 8/16

    name.dat

    Also: pset, pscheck-in:svn propset svn:eol-style LF file-name.txt

    See YoLinux Subversion server configuration tutorial:No ctrl-M.

    Subversion and Graphical diffs for Linux:

    Three types of file differences are covered in this section:

    1. Show file differences made since checkout was made. This shows the changes you have made. It isusefull to perform this before an update.

    2. Show file differences between two files versions stored in Subversion.3. Show differences / conflicts, choose and merge. Use our bash script svndiffwrapper which integrates

    into Subversion's file check-in process.

    1) File differences since checkout:

    The following scripts will allow you to view the changes you have made since checkout. Use the scriptbefore running "svn update" as an update will alter the file with diff chevron (>>>>) markers. Afterperforming a "svn update", use tkdiff, gtkdiff or kdiff3 as described below instead of the scripts:

    Use the following bash shell script to use the graphical diff tool "mgdiff" with Subversion.

    svndiff:

    01 #!/bin/bash02 # svndiff 1.003 # usage: svndiff file04 05 # No longer valid for SVN 1.7 and later06 # (no .svn/ in each directory. Now only at top directory)07 #if [[ ! -d .svn ]]08 #then09 # echo ERROR: You are not working in an SVN directory.10 # exit 111 #fi12 13 rev="--revision HEAD"14 15 if [[ ! -n $1 ]]16 then17 echo "Usage: svndiff [option] file"18 echo "Options:"19 echo " -h Diff with latest in repository (HEAD) - Default"20 echo " -b Diff with what you had checked out (BASE)"21 echo " -c Diff with COMMITTED, the version before BASE"22 echo " -p Diff with PREV, the version before COMMITTED"23 echo " -r revnum Diff with specified revision (specify integer)"24 exit 125 fi26 27 while getopts ":r:hbcp" Option28 do29 case $Option in30 h) rev="--revision HEAD";;31 b) rev="--revision BASE";;32 c) rev="--revision COMMITTED";;33 p) rev="--revision PREV";;34 r) rev="--revision $OPTARG";;35 *) echo "Incorrect option specified. Use -h or -b or -r #";;36 esac37 done38 shift $(($OPTIND -1))39 40 # Define graphical diff tool41 #42

    43 # dif="/usr/bin/kompare"44 45 # The geometry option used by Motif, Tcl and X based programs

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 9/16

    Compares your current local copy with the latest in the repository (Default "-h").

    OR

    Use the following bash shell script to use the graphical diff tool "gvimdiff:" with Subversion:

    svndiff:

    Compare your current local copy with the original copy you checked out.

    2) File differences between two revisions:

    This configuration supports the use of GUI diff tools with Subversion by using the command: svn diff -r457:459 --diff-cmd

    Some diff tools are supported with native svn. i.e.: svn diff -r 457:459 --diff-cmd kdiff3 file-namewhile others require a wrapper script to arrange the arguments correctly.

    Subversion configurations and defaults are specified in the file: $HOME/.subversion/config

    ..

    ...

    46 geometry="-geometry 1280x800+0+0"47 48 # The following is for Motif diff49 # -w: ignore white space50 dif="mgdiff -args -w"51 52 file=$153 prev=${file}_PREV54 55 # Trap bash command signals56 # SIGINT 257 # SIGQUIT 358 # SIGTERM 1559 trap "rm -f $prev" 2 3 1560 svn cat $rev $file > $prev 2>/dev/null61 $dif $geometry $prev $file62 63 sleep 164 rm -f $prev

    01 #!/bin/bash02 # usage: svndiff file03 04 # No longer valid for SVN 1.7 and later05 # (no .svn/ in each directory. Now only at top directory)06 #if [[ ! -d .svn ]]07 #then08 # echo ERROR: You are not working in an SVN directory.09 # exit 110 #fi11 12 # Define graphical diff tool13 #14 15 dif="gvimdiff \"+colo morning\" -R"16 17 file=$118 prev=PREV_${file}19 20 # Trap bash command signals21 # SIGINT 222 # SIGQUIT 323 # SIGTERM 1524 trap "rm -f $prev" 2 3 1525 svn cat $file > $prev 2>/dev/null26 $dif $prev $file27

    28 # Sleep for non-blocking apps like gvimdiff.29 # Allow gvimdiff to read file before it is deleted.30 sleep 231 rm -f $prev

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 10/16

    [helpers]editor-cmd = gedit

    diff-cmd = /opt/bin/diffScript

    diff3-cmd = /opt/bin/diff3Script

    ...

    ..

    This configuration configures Subversion to execute the script /opt/bin/diffScript to launch yourown diff toolwith the command: svn diff -r Old:New URL.

    File: /opt/bin/diffScript

    Note: To debug what is passed as a command line argument to the diff tool, set the diff-cmd to "echo":

    ..

    ...

    [helpers]diff-cmd = echo

    ...

    ..

    This configuration echos to the screen the command line arguments being passed to the diff toolwhen the following command is executed: svn diff .....

    i.e. -u -L d0/f01.cpp (revision 1) -L d0/f01.cpp (working copy) d0/.svn/text-base/f01.cpp.svn-based0/.svn/empty-file

    3) Conflicts, file differences and merge:

    tkdiff: Subversion conflict resolution merge: tkdiff -conflict file1.cpp Select from tkdiff toolbar: "Merge" + "Show Merge Window" to open third results window.

    kdiff3 diff and merge: svn diff -r 457:459 --diff-cmd kdiff3 --extensions '-m' file-name

    svndiffwrapper: Bash script to add options to Merge|Ignore|Accept|Revert etc as a result of acheck-in. This script does it all!!

    Edit file: $HOME/.subversion/config

    ...

    [helpers]diff-cmd = svndiffwrapperdiff3-cmd = svndiffwrapper

    ...

    01 #!/bin/bash02 03 LeftLabel=$304 RightLabel=$505 LeftFile=$606 RightFile=$707 08 #gtkdiff $LeftFile $RightFile09 tkdiff $LeftFile $RightFile -L "$LeftLabel" -L "$RightLabel" &10 11 # wait for command to finish12 wait

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 11/16

    Use our bash script svndiffwrapper to perform this integrated task. By default, uses kdiff3 for difftool. Can also specify your own choice of diff tool. Place the script in /opt/bin/ for global use or $HOME/bin/ for private user access and setpermissions so that script execution is allowed: chmod ugo+x /opt/bin/svndiffwrapper

    List of graphical diff and merge tools:

    tkdiff: [download] Comes with tkcvs Subversion GUI front-end. Examples of Subversion diffs with tkdiff: (See: tkdiff --help)

    tkdiff old-URL@revA new-URL@revB

    tkdiff -r457 -r459 file-name

    Note: Use command "svn log file-name" to view valid revision numbers for the file. Referencinginvalid revision numbers as input to tkdiff will not work.gtkdiff: Has diff3 and merge features. Written with GTK+. After gtkdiff-0.8.0, GNOME desktoprequired.diffUse: Diff/merge GUI tool. Good line matching features. Supports Unicode.kdiff3: Graphical directory and file diff, merge and edit. KDE3/Qt based. Supports drag and drop.Comes with S.u.S.E. distro. (Cross platform) MS/Windows download available. A very good directoryand file diff and merge tool.

    Difference: kdiff3 file1 file2Difference: kdiff3 file1 file2 file3Difference of two files: kdiff3 directory1/file directory2Difference: kdiff3 directory1 directory2Merge: kdiff3 directory1 directory2 -o dest-directoryMerge: kdiff3 file1 file2 -mMerge: kdiff3 file1 file2 -o output-fileDiff with SVN: svn diff -r 457:459 --diff-cmd kdiff3 file-name

    Kompare: Ships with (RHEL6/RHEL5/RHEL4/FC3+) KDE SDK. [manual] Included in RPM package "kdesdk". [Potential Pitfall]: RPM installation error:

    error: Failed dependencies: perl(DCOP) is needed by kdesdk-3.5.4-3.el5.i386

    Solution: Install the dependency package "kdebindings".mgdiff: Motif-based graphical file difference browser and merge. Comes with S.u.S.E. distro.Meld: Compare, edit and merge.xxdiff: Compare 2 or 3 files and merge. Also compares directories.gvim and gvimdiffBeyond Compare - commercial tool (cross platform)

    Subversion GUI interfaces for Linux:

    TkSVN / TkCVS: Tcl/Tk based GUI. A very good Unix/Linux and MS/Windows GUI front-end toSubversion. Simple to install (requires tk). Supports GUI diff/merge, branching, tagging, editing,check-in/check-out, ... Installation to /usr/local/bin and lib (Add to your path.): (requires RPM: tk version 8.4+)

    tar xzf tkcvs_8_0_3.tar.gz

    cd tkcvs_8_0_3

    ./doinstall.tcl -nox /opt

    Configuration: (See: ~/.tkcvs)

    Set default editor and diff tool:

    ...set cvscfg(editor) "xterm -e vim"set cvscfg(tkdiff) "tkdiff"

    Also see default config file: /opt/lib/tkcvs/tkcvs_def.tcl Sets default editors for various file types. Set editor to "gedit" for rookies.

    If you want to run TkSVN / TkCVS on MS/Windows, download Tk for MS/Windows. It can also be runfrom the Cygwin environment using Tk provided in the Cygwin shell.Tigris.org: RapidSVN: Dependent on wxWidgets cross platform C++ GUI API.

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 12/16

    Download RPMs from RpmForge.org:rapidsvn-0.7.2-1.2.el4.rf.i386.rpmwxGTK-2.4.2-5.2.el4.rf.i386.rpm

    pysvn: Python subversion front-end. (cross platform) [download]eSVN: qt based GUI. Mediocre.KdeSvn: KDE front-end.Subcommander: Subversion GUI client with visual diff and merge tool with support for different textencodingsSubview: GTK based subversion (1.3+) client.JSVN: Java SVN clientSyncro SVN Client - Commercial product. Editor, diff tool and SVN client in one integrated tool.

    Web Clients:

    Kamikaze-qscm: Web based front-end similar to Mozilla Bonsai.ViewSVN: PHP4Easy SVN: PERL cgi

    Plug-ins:

    Rabbitvcs: GNOME Nautilus file browser SVN plug-in. Google code project to develop TortoiseSVNclone in Linux Nautilus file manager. Best prospect for my next favorite SVN client. Will also supportother Gnome applications. YoLinux RabbitVCS tutorialNaughtySVN: GNOME Nautilus file browser SVN plug-in.Ksvn: Subversion client plugin for the KDE Konqueror browser.Eclipse plug-ins:

    Tigris.org: subclipse Also see: C/C++ development environment and EclipseSubversive

    Note: A Subversion client is built into many of today's development IDEs such as NetBeans.

    Comparison chart of Subversion clients

    Subversion Security Tips:

    One should be aware of a possible Subversion client security hole. The Subversion client authentication willcache your login and password in your home directory in non-encrypted clear text. It will have file systemsecurity so others can not read the file however, it still is visible by root or by a root user of the file server ifone is used for home directories.

    Here are three solutions to reduce this potential security vulnerability:

    1. Don't allow Subversion to cache the password: svn commit -F file.txt --no-auth-cache This will request a username and password but will not store it.

    2. Set the Subversion configuration file on server to not cache:

    [auth]store-auth-creds = no

    3. Delete cached files when you logout. Reduces risk but does not eliminate it. This uses the bash shelllogout script to perform a clean-up of the authentication files.

    File: ~/.bash_logout

    Subversion utility commands and scripts:

    1 rm ~/.subversion/auth/svn.simple/*

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 13/16

    Command Description

    svnversion

    local-path

    This svn admin command will produce a compact version number for a workingcopy. Lists range of versions, adds "S" if switched, "M" modified.

    svnchangesinceShows the changes to the subversion repository since the local copy was lastupdated.

    svnlastlogDisplays the last log message that pertains to the current working copy. Simplifiedsvnlastchange.

    svnlastchangeDisplays the last log message and a unified diff of the changes made in the lastcommit.

    svn-clean Removes all the files and directories that are not in Subversion.

    Report Generation:

    Often one will have to generate a report or source list. The following awk script and command will generatea simple source version description report:

    File: svd_report.awk

    Command to generate the report:

    From working repository: svn info -R * | awk -f svd_report.awkFrom SVN URL: svn info -R http://cm.megacorp.com/svn/ProjX/trunk | awk -fsvd_report.awk

    The Subversion "info" command will generate a dump of information about all of the files underSubversion control recursively (-R) through all subdirectories. The AWK script will parse the outputand generate a simple report. The AWK script views the Subversion output as an AWK recordseperated by blank line where the content of each line is deliminated by the ":" (colon).

    For more information on AWK scripts, see the awk man page

    This can be used by a web bash CGI script SubversionSVD.cgi to perform this task via the web.

    Subversion Best Practices:

    ALWAYS compile and test before checking in source code. Subversion revisions should correspondto revisions which compile.Always add check-in comments. Nothing is more obnoxious that looking at a blank log or informationhistory.Monstrous binary files like CD or DVD ISO images are better suited for storage on a file systemrather than in Subversion. Subversion will not be able to show differences betwen version and will beslower than a raw filesystem.Don't copy, rename and move directories and files with system shell commands. Use Subversioncommands to "rm", "mv", and "add" directories and files and then commit changes when done. Workwithin Subversion.Commit changes as a single logical changeset for one purpose. Thus all code changes for a singlebug fix or enhancement should be checked-in together. This allows one to better follow the history logof changes.

    Check-in code at the directory level and all changed files, recursively in the directory andsubdirectories will be checked in together. svn ci -m "Check-in comment goes here" ./

    1 BEGIN { RS="";2 FS = "\n";3 printf("%-75s %10s %10s %-45s\n","Path","Cur Rev","Last Rev","Last

    Change Date"); }4 /^Path:/ { n1 = split($1,path,":");5 n2 = split($6,curRev,":");6 n3 = split($9,lastRev,":");

    7 n4 = split($10,changeDate,": ");8 printf("%-75s %8s %8s %-45s\n", path[2], curRev[2], lastRev[2],

    changeDate[2]); }

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 14/16

    Check-in files together by specifying them explicitly: svn ci -m "Check-in comment goes here" file.cpp file2.cpp ...

    Tie Bug tracking and Subversion CM together:Use comments when checking-in files into Subversion. Add bug tracking numbers to thecomments so Subversion will reference Trac bugs.If using Trac, add trac comments so that links are generated to the Subversion repository byplacing the Subversion revision number in square braces (i.e. [1140]) in a Trac comment. In thisway, Trac will have a direct URL link to Subversion.

    If using Trac integrated with Subversion, refer to the Trac ticket in the Subversion check-in commentusing a "#" in front of the Trac ticket number (eg. #65) This generates a hyperlink when theSubversion logs are viewed in Trac.Taking code from a Subversion repository for upload to another: Use "svn export" and NOT "svnco" if you want files for upload into another CM repository. A checkout (svn co) will create Subversionmanagement directories (.svn/) in the local working copy. You will not want to upload this directoriesinto a CM system as they are only for the user's local working directory only. An "export" will notcreate this directory.The "tags" branches are NOT to be used as working branches but are snapshots of an existingbranch. The "tags" are for historical reference such as a release, well tested version or progressmilestone.Documentation and related artifacts should not be under the source tree but parallel to it. Thisisolates the source tree so that email notification triggers sent to developers upon source changeswill only go out on source changes or regression build and test systems like Jenkins or Cabie will onlyrebuild and test on source changes rather than on unrelated documentation changes.

    Tips:

    Using Eclipse IDE with Subversion:

    Block Eclipse from viewing the hidden ".svn/" directories so that Eclipse does not intrude or alter theircontents:

    Select the toolbar options: "Project" + "Properties"Select the "Java Build Path" + select the "Source" tabSelect the "Excluded" item and select "Edit"In the lower half under "Exclusion patterns:" select "Add..." and enter the pattern **/.svn/*

    Note that SVN version 1.7 and later generate a single .svn/ directory at the top directory and no longerproduce a .svn/ directory in each subdirectory.

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 15/16

    Links:

    YoLinux Tutorial: Subversion Server and Trac Server Installation and Configuration

    YoLinux Tutorial: Cabie Build System - Installation and Configurationsvnbook.red-bean.com: Open Sourced version of O'Reily Book

    Subversion 1.1 - single pageSubversion 1.1 - multi-page

    Reference card [pdf]Subversionary: Subversion advocacy web site.Integrating JDeveloper and Subversion

    Books:

    Version Control with Subversion by C. Michael Pilato ISBN #0596004486, O'Reilly Press

    Practical Subversion (Expert's Voice in Open Source) Garrett Rooney ISBN #1590592905, Apress

    Subversion Version Control: Using the Subversion VersionControl System in Development Projects William Nagel ISBN #0131855182, Prentice Hall PTR

  • 1/31/2014 Subversion Commands and Scripts

    http://www.yolinux.com/TUTORIALS/Subversion.html 16/16

    YoLinux.com Home Page YoLinux Tutorial Index | Terms Privacy Policy | Advertise with us | Feedback Form | Unauthorized copying or redistribution prohibited.

    StumbleUpon487

    18

    to top of page

    Copyright 2006-2013 by Greg Ippolito

    SVN 1.8www.vercue.com

    The Free and Most Feature-RichAutomated Subversion 1.8 Client