SVN: How to know in which revision a file was deleted?

Viewed 11198

Given that I'm using svn command line on Windows, how to find the revision number, in which a file was deleted? On Windows, there are no fancy stuff like grep and I attempting to use command line only, without TortoiseSVN. Thanks in advance!

EDIT:

  • I saw a few posts, like examining history of deleted file but it did not answer my question.
  • Is there any way other than svn log -v url > log.out and search with Notepad?
3 Answers

This question was posted and answered some time ago. In this answer I'll try to show a flexible way to get the informations asked and extend it.

In cygwin, use svn log in combination with awk

REPO_URL=https://<hostname>/path/to/repo
FILENAME=/path/to/file

svn log ${REPO_URL} -v --search "${FILENAME}" | \
    awk -v var="^   [D] ${FILENAME}$" \
    '/^r[0-9]+/{rev=$1}; \
    $0 ~ var {print rev $0}'
  • svn log ${REPO_URL} -v --search "${FILENAME}" asks svn log for a verbose log containing ${FILENAME}. This reduces the data transfer.
  • The result is piped to awk. awk gets ${FILENAME} passed via -v in the var vartogether with search pattern var="^ [D] ${FILENAME}$"
  • In the awk program /^r[0-9]+/ {rev=$1} assigns the revision number to rev if line matches /^r[0-9]+/.
  • For every line matching ^ [D] ${FILENAME}$ awk prints the stored revision number rev and the line: $0 ~ var {print rev $0}

if you're interested not only in the deletion of the file but also creation, modification, replacing, change Din var="^ [D] ${FILENAME}$"to DAMR.

The following will give you all the changes:

svn log ${REPO_URL} -v --search "${FILENAME}" | \
    awk -v var="^   [DAMR] ${FILENAME}$" \
    '/^r[0-9]+/ {rev=$1}; \
    $0 ~ var {print rev $0}'

And if you're interested in username, date and time:

svn log ${REPO_URL} -v --search "${FILENAME}" | \
    awk -v var="^   [DAMR] ${FILENAME}$" \
    '/^r[0-9]+/ {rev=$1;user=$3;date=$5;time=$6}; \
    $0 ~ var {print rev " | " user " | " date " | " time " | " $0}'
Related