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



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

有人问我如何处理固件的版本,所以我告诉他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 是最糟糕的选择

他希望能够随时回到以前的版本。 同时,他想看看修改

这是任何 SCM 的自然任务,他可以选择这个("任何")VCS,具有良好的不过度膨胀的 GUI(对于线性历史甚至 SVN|SVN将是不错的选择)

从 Java 调用 Git 是,真的

最新更新