Subversion notes

From raju

filtering the log messages

svn log between two dates

    svn log -r {2017-09-01}:{2017-10-31} | less
    

svn log between two dates by a particular author

    svn log -r {2017-09-01}:{2017-10-31} --search author_foo | less
    

svn log by a particular user in the last N commits

    svn log --search author_foo -l N | less
    


Increase the context when doing svn diff

By default, svn diff shows three lines of context. To change it to 10

    svn diff FILENAME --diff-cmd=diff -x -U10
    

See

    svn help diff
    

for explanation of the arguments and generic use cases.

Related Links:

tags | svn diff more context

What files changed locally?

List files that are locally changed

Most generic way

  • using perl
=> svn st | perl -ne '{ next if /^\?/; if (/(\S+)$/) {print "$1\n";} }' | xargs -r ls -al --time-style="+%Y%m%d_%H%M"

The -r argument to xargs tells not to run the command if there are no arguments. Useful in the corner case where no files tracked by svn are modified.

Other possible ways

  • Using grep and cut
=> svn st | grep -v '^?' | cut -c 9- | xargs -r ls -al --time-style="+%Y%m%d_%H%M"

This does not work if GREP_OPTIONS is set to display line numbers in the output of grep. In that case the filename may not start from 9th character. See the perl version above which does not have this issue.

  • Using grep and awk
=> svn st | grep -v '^?' | awk '{print $2}' | xargs -r ls -al --time-style="+%Y%m%d_%H%M"

This does not work if the svn st output contains lines of the form

A  +    file.c

See the perl version above which does not have this problem.

What changed in a version?

What files changed in a revision?

% svn diff --summarize -c r297

What changes were made in a revision?

% svn diff -c r297

To show the files changed in a revision as well as the commit message

% svn log --verbose -r316

What changed between versions?

What files changed between two revisions (a,b]?

% svn diff --summarize -r310:r314

What changes were made between two revisions (a,b]?

% svn diff -r310:r314

revert a commit

cd into the directory

% svn merge -c -317 .
--- Reverse-merging r317 into '.':
U    src/HotCold.C

To revert a range of commits

% svn merge -r HIGHREV:LOWREV .

To revert multiple single commits

% svn merge -c -315,308 .

keyword substitution

tag | automatic headers, keyword expansion

For Perl files I use

#! /usr/bin/env perl
#=============================
#   Last edited by:  $Author$
#               on:  $Date$
#         Revision:  $Revision$
#              url:  $HeadURL$
% svn propset svn:keywords "Author Date Revision HeadURL" script.pl

The keywords will be expanded once the file is committed.

Ref:- http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html

use vimdiff when doing svn diff

    vim_rc = subprocess.call(['vim', '-dfgR',
        '--cmd', "au BufReadPost " + lf1 + " silent f " + sanitise(n1),
        '--cmd', "au BufReadPost " + lf2 + " silent f " + sanitise(n2),
        lf1, lf2])
    

to

    vim_rc = subprocess.call(['vim', '-dfR',
        '--cmd', "au BufReadPost " + lf1 + " silent f " + sanitise(n1),
        '--cmd', "au BufReadPost " + lf2 + " silent f " + sanitise(n2),
        lf1, lf2])
    
  • chmod +x ~/bin/svndiff_helper
  • svn diff --diff-cmd ~/bin/svndiff_helper

undo an svn add

To undo an svn add file_name

    svn rm --keep-local file_name
    

list all tracked files

To list all svn tracked files in a directory

    svn list <dir>
    

Recursively, list all tracked files

    svn list -R <dir>
    

Useful external links