How do I revert a modified file using CVS?

CvsRevert

Cvs Problem Overview


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?

Cvs Solutions


Solution 1 - Cvs

You use

cvs update -C filename

Solution 2 - Cvs

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAshotView Question on Stackoverflow
Solution 1 - CvsEricView Answer on Stackoverflow
Solution 2 - CvsMortView Answer on Stackoverflow