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
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
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 <dustin@spy.net>
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.
If you don't know the path to the deleted file, turns out you can search for it in the otherwise all-too-heavy svn log
command:
svn log --search <deleted_file_or_pattern> -v
The command is probably hammering the server just as much as it would without the search option, but at least the rest of involved resources (including your eyeballs) would be kinda relieved, since that will tell you in which revision that file was deleted. Then, you can follow the other tips (mainly using the same svn log
command, but already on a defined path).
svn log -v | grep -B50 YourDeletedFileName
Will get you the path and revision. In git (also checks for renames):
git log --diff-filter=DR --name-only | grep -B50 YourDeletedFileName
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:
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.
Use this command:
svn log -v | awk '/^r[0-9]+/ { rev = $1; }; / D .*filename_escaped_for_regex/ { print rev" "$2; };'
This will list all revisions that ever deleted any files matching the pattern.
That is, if you're searching for file README, then all of /src/README
, /src/README.first
, and /some/deeply/hidden/directory/READMENOT
will be found and listed.
If your filename contains slashes (path), dots, or other special regex characters, don't forget to escape them to avoid mismatching or errors.
You would need to specify a revision.
svn log -r <revision> <deleted file>