简体   繁体   English

Java中的Git Diff命令

[英]Git Diff command in Java

For a project, I need to take a list of git commit Id's (A couple thousand), and compare them two at a time, saving specific information from the return into a file. 对于一个项目,我需要列出git commit Id的列表(几千个),然后一次将它们两个进行比较,将返回的特定信息保存到文件中。 The only issue I'm having is getting a diff command to work in Java. 我唯一遇到的问题是让diff命令在Java中工作。 I've spend hours trying to figure this out and I'm still in need of assistance. 我已经花了数小时试图解决这个问题,但我仍然需要帮助。

You can run a command and get its result using this : 您可以运行命令并使用以下命令获取结果:

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.redirectErrorStream(true);
    Process process = processBuilder.start();
    String output = readOutput(process);
    try {
        if (process.waitFor() != 0) {
            throw new IOException(
                "command exited in error: " + process.exitValue()
                    + "\n" + output);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return output;

So you just have to define the most adapted "git diff..." command for your problem and parse the output. 因此,您只需要为您的问题定义最适合的“ git diff ...”命令并解析输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM