examining history of deleted file

When you want to look at old files you really should know the difference between:

svn cat http://server/svn/project/file -r 1234

and

svn cat http://server/svn/project/file@1234

The first version looks at the path that is now available as http://server/svn/project/file and retrieves that file as it was in revision 1234. (So this syntax does not work after a file delete).

The second syntax gets the file that was available as http://server/svn/project/file in revision 1234. So this syntax DOES work on deleted files.

You can even combine these methods to retrieve a file that was available in revision 2345 as http://server/svn/project/file but with the contents as it had in 1234 with:

svn cat http://server/svn/project/file@2345 -r 1234

First, find the revision number where the file got deleted:

svn log -v > log.txt

Then look in log.txt (not an SVN guru, so I don't know a better way) for a line with

D <deleted file>

and see which revision that was. Then, as in the other answers, resurrect the file using the previous revision.


To get the log of a deleted file, use

svn log -r lastrevisionthefileexisted

If you want to resurrect the file and keep its version history, use

svn copy url/of/file@lastrevisionthefileexisted -r lastrevisionthefileexisted path/to/workingcopy/file

If you just want the file content but unversioned (e.g., for a quick inspection), use

svn cat url/of/file@lastrevisionthefileexisted -r latrevisionthefileexisted > file

In any case, DO NOT use 'svn up' to get a deleted file back!


It's nothing particularly special in git. If you know the name of the file, you can find out the change that removed it with log:

git log -n 1 -- filename

Then you can use that commit to get the file as it existed before the deletion.

git checkout [last_revision]^ filename

Example:

dhcp-120:/tmp/slosh 587% ls -l slosh.tac
ls: slosh.tac: No such file or directory
dhcp-120:/tmp/slosh 588% git log -n 1 -- slosh.tac
commit 8d4a1f1a94e4aa37c1cb9d329a140d08eec1b587
Author: Dustin Sallings <[email protected]>
Date:   Mon Dec 15 11:25:00 2008 -0800

    Get rid of a .conf and replace it with .tac.
dhcp-120:/tmp/slosh 589% git checkout 8d4a1f^ slosh.tac
dhcp-120:/tmp/slosh 590% ll slosh.tac
-rw-------  1 dustin  wheel  822 Dec 30 12:52 slosh.tac

Note that this does not actually put the file back in revision control. It simply drops the file as it existed in its final state into the current location. You can then add it or just inspect it or whatever from that point.


A solution using only the GUI:

If you know the name of the file, but don't know its last revision number or even its path:

  1. From Repo Browser do a "Show log" on the root
  2. Hit "Show All" (at the bottom of the log dialog)
  3. Type the filename into the Filter textbox (at the top of the log dialog)

This will then show only those revisions where the file was added/modified/deleted. This is your history of the file.

Note that if the file was deleted by deleting one of its parent folders, it won't have a 'deleted' entry in the log (and so mjy's solution won't work). In this case, its most recent entry in the filtered log will correspond to its contents at deletion.