gpt4 book ai didi

java - 使用java程序进行版本控制,使用DOS命令

转载 作者:行者123 更新时间:2023-12-01 12:03:47 25 4
gpt4 key购买 nike

我正在尝试做一些可能愚蠢的事情,我需要你的帮助来澄清事情。

有人问我如何处理固件的版本,所以我告诉他 git、svn 以及这两个东西附带的所有 GUI。但这并不完全是他所需要的。他是唯一负责这个固件的人,他只需要处理不同的版本。例如,如果他在 v3 上工作,他希望能够随时返回到以前的版本。同时,他希望像使用“git diff”命令一样查看修改。

为了给他想要的程序,我正在尝试编写一个java程序(也许这不是最好的选择?),它将使用他需要的一些git命令(commit,diff,reset,...)这也将提供他需要的额外功能。

如果您有建议或者我错过了什么,请告诉我。

现在,关于java程序:

我在使用“git diff”命令时遇到了一些问题。在 shell 中,没问题,我得到了所有的红线和绿线,但在 java 控制台中,没有显示任何内容。您还应该知道“git status”(例如)命令在 shell 和 java 控制台中都可以完美运行。

这是我的代码:

Scanner keyboard = new Scanner(System.in);
System.out.println("enter a git command");
String command = keyboard.nextLine();
keyboard.close();
File execute = new File("C:/.../MyGitRepository");

Process process = Runtime.getRuntime().exec(command, null, execute);

Scanner s = new Scanner(process.getInputStream());
StringBuilder text = new StringBuilder();
while (s.hasNextLine()) {
text.append(s.nextLine());
text.append("\n");
}
s.close();
int result = process.waitFor();

System.out.printf("Process exited with result %d and output %s%n", result, text );

使用“git diff”命令,我得到这个:

enter a git command
git diff

通过“git status”命令我得到这个:

enter a git command
git status
Process exited with result 0 and output On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: MyFile1.xml
modified: MyFile2.xml
modified: MyFile3.xml
...

感谢您的帮助!

最佳答案

如果相关人员之前没有任何任何 VCS 经验,那么基于 Git 是最糟糕的选择

对于

he wants to be able to come back to the former version at any time. Simultaneously, he wants to see the modifications

这是任何 SCM 的自然任务,他可以选择这个(“任何”)具有良好但不过分臃肿的 GUI 的 VCS(对于线性历史,甚至 SVN|TortoiseSVN 将是不错的选择)

从 Java 调用 Git 确实是变态

关于java - 使用java程序进行版本控制,使用DOS命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27816718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com