Fri, 08 Jan 2010

How to back date a subversion checkin

While setting up a new subversion (svn) repository for my old blog entries, I wanted to keep the original dates (mtime of the file) in the checkin commit (for use with the pyblosxom svn plugin). After a quick online research I came up with the following script:
# Jan Dittmer <> 2008
# Use at your own risk

D=`ls -l "$1" | cut -f6-7 -d' ' | sed 's/ /T/'`
echo "Date: $D"
if ! svn add "$1"; then exit 1; fi
if ! svn ci -m "Date $D" "$1"; then exit 2; fi
R=`svn info "$1" | grep "^Revision: " | cut -f2 -d' '`
echo "Revision: $R"
if [ "$R" == "" ]; then exit 3; fi
if ! svn propset --revprop svn:date -r$R "$D"; then exit 4; fi
Please note, that subversion does not do any sanity checking on the svn:date property. If svn log reports a 'Bogus Date' afterwards, make sure your dates have the format 'YYYY-MM-DDThh:mm:ss.uuuuuuZ'.

posted at 12:14 | path: /unix | permanent link to this entry

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.