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
I wrote a php script that copies the svn log of all my repositories into a mysql database. I can now do full text searches on my comments or names of files.
Ah, since I am learning to use Bazaar, it is something I tried. Without success, it appears you cannot log and annotate removed files currently... :-(
Tried:
> bzr log -r 3 Stuff/ErrorParser.hta
bzr: ERROR: Path does not have any revision history: Stuff/ErrorParser.hta
but curiously (and fortunately) I can do:
> bzr cat -r 3 Stuff/ErrorParser.hta
and:
> bzr diff -r 2..3 Stuff/ErrorParser.hta
and as suggested in the bug above:
> bzr log -v | grep -B 1 ErrorParser
(adjust -B
(--before-context
) parameter as needed).
In addition to Dustin's answer, if you just want to examine the contents, and not check it out, in his example you can do:
$ git show 8d4a1f^:slosh.tac
the : separates a revision and a path in that revision, effectively asking for a specific path at a specific revision.
Assume your file was named as ~/src/a/b/c/deleted.file
cd ~/src/a/b/c # to the directory where you do the svn rm or svn mv command
#cd ~/src # if you forget the correct directory, just to the root of repository
svn log -v | grep -w -B 9 deleted.file | head # head show first 10 lines
sample output, found it at r90440
...
r90440 | user | 2017-02-03 11:55:09 +0800 (Fri, 03 Feb 2017) | 4 lines
Changed paths:
M /src/a/b/c/foo
M /src/a/b/c/bar
D /src/a/b/c/deleted.file
copy it back to previous version(90439=90440-1)
svn cp URL_of_deleted.file@90439 .
You can find the last revision which provides the file using binary search.
I have created a simple /bin/bash
script for this:
function svnFindLast(){
# The URL of the file to be found
local URL="$1"
# The SVN revision number which the file appears in (any rev where the file DOES exist)
local r="$2"
local R
for i in $(seq 1 "${#URL}")
do
echo "checkingURL:'${URL:0:$i}'" >&2
R="$(svn info --show-item revision "${URL:0:$i}" 2>/dev/null)"
echo "R=$R" >&2
[ -z "$R" ] || break
done
[ "$R" ] || {
echo "It seems '$URL' is not in a valid SVN repository!" >&2
return -1
}
while [ "$r" -ne "$R" -a "$(($r + 1))" -ne "$R" ]
do
T="$(($(($R + $r)) / 2))"
if svn log "${URL}@${T}" >/dev/null 2>&1
then
r="$T"
echo "r=$r" >&2
else
R="$T"
echo "R=$R" >&2
fi
done
echo "$r"
}