Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find if a file have ever existed in a svn-repo?

Tags:

svn

For some obscure (but valid) reasons I need to find out if a file ever have been versioned in our repository.

I have only found an roundabout way of getting the log for the containing dir and then parse it for removed entries:

svn log -v a/b/|grep "   D .*a/b/c.xml"

It works, but feels "unclean" and somewhat fragile.

like image 785
Mr Shark Avatar asked Mar 05 '12 09:03

Mr Shark


People also ask

How do I find my svn file history?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

How do I find previous versions in svn?

On the file, simply right-click => Team => Switch to another branch/tag/revision. Besides the revision field, you click select, and you'll see all the versions of that file.

How do I view svn logs?

Examples. You can see the log messages for all the paths that changed in your working copy by running svn log from the top: $ svn log ------------------------------------------------------------------------ r20 | harry | 2003-01-17 22:56:19 -0600 (Fri, 17 Jan 2003) | 1 line Tweak.

How do I find svn modified files?

To get an overview of your changes, use the svn status command. You may use svn status more than any other Subversion command. If you run svn status at the top of your working copy with no arguments, it detects all file and tree changes you've made.


1 Answers

Based on your question, you are implicitly qualifying your request to deleted files (because presumably if it is not deleted a simple directory search would reveal it). Lazy Badger's comment is worthy: removing the qualification without losing any accuracy and thereby simplifying the command. I am all in favor of simplifying but given any problem I also like to consider getting more out of a solution at little additional cost.

So starting with your proposed solution:

svn log -v a/b/ | grep "   D .*a/b/c.xml"

I would first add the -q option, which cuts down on output that you are just discarding anyway:

svn log -v -q a/b/ | grep "   D .*a/b/c.xml"

And then I would want to know not just whether there was such a file deleted but also when it was deleted (i.e. in which revision). Since you also implicitly qualified your environment to Unix/Linux, here is a solution with awk (adapted from this blog entry):

svn log -q -v a/b/ | awk '
    /^r[0-9]* \|/ { REVISION=$1; }
    /  D/ { print REVISION": "$0; }
' | grep "   D .*a/b/c.xml"

That works because of the format of the svn log output when the –v parameter is used: it reports a revision followed by all the files in that revision. Here’s an example showing that the file Page.cs was deleted in revision 10506:

r10506 | msorens | 2011-02-14 12:58:56 -0800 (Mon, 14 Feb 2011) | 1 line
Changed paths:
   A /Projects/Test/Common
   A /Projects/Test/Common/Setup.cs
   A /Projects/Test/Common/Utility.cs
   D /Projects/Test/Page.cs

The awk commands above parse output in this format extracting the revision number from the top line then any files marked as deleted (the “D” lines). For Windows, PowerShell provides the same power and ease of use as awk by using the switch statement:

$( switch -Regex (svn log -q -v a/b) {
    '^(r[0-9]*) \|' { $rev = $Matches[1] }
    '^   D\s+(.*)'  { "{0,-6} {1}" -f $rev, $Matches[1] }
} ) | Select-String "a/b/c.xml"

But there is an easier way with TortoiseSVN---just open up the log window on the root of your working copy and type in the file name in the search box. The list of revisions immediately filters by whatever you type. If it shows more than one line of output, the latest (topmost) revision will always be the one where the file was deleted.

like image 193
Michael Sorens Avatar answered Nov 07 '22 08:11

Michael Sorens