Thursday, August 8, 2013

Svn file full history

If you’d need to search in the full history of a file stored in SVN, the script below can make an export of all changes ever applied into a file, starting for the first revision (full file) and adding each time an overview of all changes applied.

If you remember you ever applied some changes in a file, but removed it afterwards, this can help to search in the full history. Only tested on text based files.

For each revision, the revision number, author, timestamp and svn comments will be listed, followed by an overview of the removed lines, added lines, update lines etc. The initial revision will be a full extract of the original file.

Usage: save the SvnFileFullHistory.bat script in an SVN folder next to the file for which you’d need a full history extract. Drop the svn file onto the bat script to start the script and retrieve the full history of the dropped svn file. The full svn file history will be saved in a txt file in the same folder and with the same base name as the file to extract, but adding “-FullSvnHistory.txt” behind the file name. The extract can take a while, depending on the number of revisions and the size of the svn file. But while the extract is ongoing, the “…-FullSvnHistory.txt” can be read already, reloading it to get future updates.

A similar linux shell script has been created as well (not fully tested).

Based on information found on stackoverflow by user ladenedge.

Full script content:

@echo off   
TITLE SVN - Full file history
REM Original source: and
echo Copy this bat script next to the checked out svn file on which to get full svn history. Drag and drop the svn file onto the bat script to start fetching the info (or a open command window and provide the name of the svn file as first parameter to the bat script execution)
if "%1%"=="" pause
set file=%1
set report=%file%-FullSvnHistory.txt
if [%file%] == [] (
  echo Usage: "%0 <file>"
  exit /b
echo Retrieving svn history of file, please wait...
echo The report will be saved in the file: %report%.
echo To stop the process press Ctrl+c.
rem first revision as full text
for /F "tokens=1 delims=-r " %%R in ('"svn log -q %file%"') do (
  svn log -r %%R %file% > %report%
  svn cat -r %%R %file% >> %report%
  goto :diffs
rem remaining revisions as differences to previous revision
for /F "skip=2 tokens=1 delims=-r " %%R in ('"svn log -q %file%"') do (
  svn log -r %%R %file% >> %report%
  svn diff -c %%R %file% >> %report%

No comments:

Post a Comment