If I delete a file in Subversion, how can I look at it\'s history and contents? If I try to do svn cat
or svn log
on a nonexistent file, it complai
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!
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
If you're wanting to look at the history of a file prior to it being renamed, then as mentioned in a comment here you can use
git log --follow -- current_file_name
I wanted an answer, myself. Try the following to output only deletes from svn log
.
svn log --stop-on-copy --verbose [--limit <limit>] <repo Url> | \
awk '{ if ($0 ~ /^r[0-9]+/) rev = $0 }
{ if ($0 ~ /^ D /) { if (rev != "") { print rev; rev = "" }; print $0 } }'
This filters the log output through awk. awk buffers each revision line it finds, outputting it only when a delete record is found. Each revision is only output once, so multiple deletes in a revision are grouped together (as in standard svn log
output).
You can specify a --limit
to reduce the amount of records returned. You may also remove the --stop-on-copy
, as needed.
I know there are complaints about the efficiency of parsing the whole log. I think this is a better solution than grep and its "cast a wide net" -B
option. I don't know if it is more efficient, but I can't think of an alternative to svn log
. It's similar to @Alexander Amelkin's answer, but doesn't need a specific name. It's also my first awk script, so it might be unconventional.
The poster has actually asked 3 questions here:
All the answers I see here are for questions 2 and 3.
The answer to question 1 is:
svn log http://server/svn/project/file@1234
You still need to get the revision number for when the file last existed, which is clearly answered by others here.