examining history of deleted file
Solution 1
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!
Solution 2
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
Solution 3
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.
Solution 4
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.
Solution 5
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:
- From Repo Browser do a "Show log" on the root
- Hit "Show All" (at the bottom of the log dialog)
- 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.
Related videos on Youtube
Comments
-
Benjamin Peterson over 4 years
If I delete a file in Subversion, how can I look at it's history and contents? If I try to do
svn cat
orsvn log
on a nonexistent file, it complains that the file doesn't exist.Also, if I wanted to resurrect the file, should I just
svn add
it back?(I asked specifically about Subversion, but I'd also like to hear about how Bazaar, Mercurial, and Git handle this case, too.)
-
rmeador over 15 yearsYou can also ressurrect the file by doing a reverse merge of the revision in which you deleted it. This is the procedure recommended in the SVN docs. As for using "svn up", it's not so much a matter of "don't do it" as it is "it will not do what you want it to do".
-
Benjamin Peterson over 15 yearsHow can I see the file's whole history, though?
-
rmeador over 15 yearsI'd edit the answer if I could, but since I can't, the way to get the whole log is to use a revision range of the form 1:lastrevisionfileexisted (or perhaps it starts at zero... can't remember)
-
abatishchev over 15 yearssvn log -v | grep D "file.name"
-
Dustin over 15 yearsAh, very true. I used to do that the really, really hard way. :)
-
Wayne E. Seguin over 15 yearsThis gives an error. Example: svn log -r 37428 svn.example.com/deletedfile.java svn: '/!svn/bc/98571/deletedfile.java' path not found
-
Stefan over 15 yearsSimple: show the log for a parent folder with the '-v' switch: you'll get for every entry a list of changed paths. Find the one with a 'D' in front and the name of your deleted file. That's the revision where the file got deleted.
-
Jack M. over 15 yearsAre you sure it existed at that revision? You have to specify a revision where the file actually existed.
-
Keith Palmer Jr. over 14 yearsGah, thanks! The current top response in this thread does not mention this, this is great!
-
Keith Palmer Jr. over 14 yearsThis doesn't seem to work for deleted files. If I try this, I get this error message: svn cat [url]/trunk/include/syeka/poster_funk.incl.php -r 50 > out.txt svn: '/admintools/!svn/bc/131/trunk/include/syeka/poster_funk.incl.php' path not found See @Bert Huijben's response further down this thread for a working solution.
-
Cerin almost 14 years+1 for being the first person to correctly answer the question. You can't look at the contents if you don't know the revision before it was deleted.
-
dubek over 13 yearsSee the answer by Bert Huijben for the weird different between -r37428 and adding @37428 to the SVN URL.
-
tchen over 12 years@abatishchev this obtains the list of deleted files, but discards the revision info, so it's not useful. Also it's slow if you're working with a large/old repository with much change history.
-
Mars almost 12 yearsBrute force is not always the shit. Especially not on big repos.
-
Mars almost 12 yearsGood, great with @abatishchev's improvement. tchen: easily fixed using a -B50 or so argument to grep, see my answer.
-
Mir over 11 years+1 for a UI only solution. Command line is great, and all, but it's not always the best answer without exception. Especially when you're working in an environment you don't control, and don't have easy command line access to SVN.
-
Derrick Rice about 11 yearsThis still failed for me unless I used absolute paths, since my local svn client was giving an error when unable to resolve
./local/file
when the./local
directory did not exist. This might not be a problem for newer versions of SVN. -
musiphil almost 11 years@DerrickRice: In that case, the
^
notation comes handy: it refers to the repository root, so you can saysvn cat ^/local/file@REV
(depending on the distance between the repository root and URL). -
mindmatters over 10 yearsAnother good way to limit the svn log -v output for very large/old repositories is the -l option. So you could use svn log -v -l 100 | grep D "file.name"
-
Barney about 10 yearsThis works great in principle. For folders I receive the following:
svn: E200009: Could not cat all targets because some targets are directories
-
Felipe Alvarez about 10 yearsThis is the best answer. Has the highest votes, too.
-
wytten about 10 yearsThis is the answer you are looking for. Not sure how the accepted answer achieved that many votes or got accepted because it doesn't work as far as I can tell.
-
thinsoldier over 9 years
svn log --search _test2.php -v
... svn: invalid option: --search ... :( -
cedd almost 9 yearsWhat does the -B50 do? I can get a list of files using svn log and grep quite easily using the tips here, but I can't seem to get the revision numbers displayed at all easily, being as they are displayed on a different line. I tried the B50 thing and it didn't seem to work that amazingly for me.
-
cedd almost 9 yearsIt outputs the mathced line and the 50 lines above that in case anybody else is reading this.
-
Jon Watte almost 8 yearsIf I have a repo with 100,000 commits, "lastrevisionthefileexisted" is not easy to find!
-
Kevin over 7 yearsfor rev in {900..600}; do if svn cat server/repo/file.ext@$rev > /dev/null 2>&1; then echo "Last seen at revision: $rev"; break; fi; done
-
inquam about 7 yearsIf you know the name of the file, or part of it, but don't remember when you deleted it you could use this quick script I threw together a few years back: github.com/inquam/svn-find-deleted-file
-
JohnK almost 7 yearsWonderful answer. Only problem is that the question is about svn!
-
Georg Muehlenberg over 4 yearsPlease note that the above answer is meant for the TortoiseSVN GUI.
-
Arseni Mourzenko about 3 yearsAs the post makes no attempt to answer the original question which is explicitly about Subversion, consider downvoting it in order to give it a chance to be removed.