How do I revert a modified file using CVS?
Asked Answered
F

2

53

I have checked out a file from CVS repository and changed it.

cvs up command says that the file is modified M.

I need to delete my changes. What cvs command can do it for me?

Fetlock answered 29/3, 2013 at 14:9 Comment(3)
You can do override and update.Perfidious
If you deleted the file, and did a cvs up, wouldn't that restore it? And SVN has a revert command too, doesn't CVS too?Emarie
@Emarie It doesn't. Delete + update is the way to go.Palpable
A
80

You use

cvs update -C filename
Academe answered 18/4, 2013 at 7:51 Comment(2)
It updates to latest version. What about recovering the same revision.Fetlock
you can use -r revision and specify the revision you want.Valenza
S
1

It's a surprisingly complicated to do. We ended up using this script "cvsunedit". Which I admit looks like overkill, but there are things in cvs that are just harder to do than they should be.

#!/bin/bash
# cvsunedit - revert a file's modifications while preserving its current version
set -e
if [ "$1" = "" ]
then
    exit 0
fi
for f in $*
do
    echo "$f"
    base="$(basename "$f")"
    dir="$(dirname "$f")"
    rev="$(perl -e "while(<>){m#/$base/([^/]+)/# && print \$1 . \"\n\";}" < "$dir/CVS/Entries")"
    if [ "$rev" = "" ]
    then
        echo "Cannot find revision for $f in $dir/CVS/Entries"
        exit 1
    fi

    executable=0
    [ -x "$f" ] && executable=1

    mv "$f" "$f.$$.rev$rev.bak" || rm -f "$f"

    set -x
    cvs up -p -r "$rev" "$f" > "$f"
    set +x
    chmod -w "$f"
    [ $executable -ne 0 ] && chmod aog+x "$f"
done
exit 0
Separator answered 29/9, 2019 at 21:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.