如何在CVS中获取文件特定版本的先前版本

问题描述

|| 给定文件名及其修订版本,是否有任何CVS命令可以给我文件的先前修订版本?     

解决方法

您可以使用cvs history命令。     ,CVS控制文件版本的方式是仅在该文件中有提交时才增加修订。树或标签等中的更改不会影响单个文件的修订。 尽管没有确切的方法来获取文件的先前修订版,但要给出名称及其修订版...但是围绕它有一种命中和试用的方法。盲目去上一个版本。例如,先前的版本“ 0”将是“ 1” 解决这个问题的另一种方法是编写一个shell脚本。使用
cvs log
获取特定文件名的更改日志,然后grep所需的修订号。     ,没有直接的方法可以从CVS命令执行此操作。但是,由于我在Java中使用(CVS日志的)输出,因此以下代码段对我有用
if (currentRevision == null || currentRevision.trim().length() == 0) {
    return null;
}

String[] revComponents = currentRevision.trim().split(\"\\\\.\");

if (revComponents == null || revComponents.length == 0) {
    log.warn(\"Failed to parse revision number: \" + currentRevision
            + \" for identification of previous revision\");
    return null;
}

if (revComponents.length % 2 == 1) {
    log.warn(\"Odd number of components in revision: \" + currentRevision);
    log.warn(\"Possibly a tag revision.\");
    return null;
}

int lastComp;
try {
    lastComp = Integer.parseInt(revComponents[revComponents.length - 1]);
} catch (NumberFormatException nmfe) {
    log.warn(\"Failed to parse the last component of revision from \" + currentRevision);
    log.warn(\"Identified presence of alphanumric values in the last component. Cannot predict previous revision for this\");
    return null;
}

if (revComponents.length == 2 && lastComp == 1) {
    log.debug(\"Revision: \" + currentRevision + \" is the first revision for the current file. Cannot go further back\");
    return null;
}

StringBuilder result = new StringBuilder();
if (lastComp == 1) {
    for (int i = 0; i < revComponents.length - 2; i++) {
        if (result.length() > 0)
            result.append(\'.\');
        result.append(revComponents[i]);
    }
} else if (lastComp > 1) {
    for (int i = 0; i < revComponents.length - 1; i++) {
        result.append(revComponents[i]);
        result.append(\'.\');
    }
    result.append((lastComp - 1));
} else {
    log.warn(\"Found invalid value for last revision number component in \" + currentRevision);
        return null;
    }

    return result.toString();
}
上面的代码还处理分支修订,例如,如果当前修订(如图所示)是分支上的第一个修订,则它将返回从中创建该文件的分支的修订。 希望这可以帮助。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...