java 执行git命令 是通过
Runtime.getRuntime().exec();
以git clone为例
public String cloneTFSCode(String path,String branch){ String result=""; try { // 替换为你的TFS代码仓库URL和本地目录 String tfsRepoUrl = "repoURL"; String localPath = path+"\\CODE"; // 构建Git克隆命令,每个命令中间都以,分割 String[] cmd = new String[]{"git", "clone","-b",branch, tfsRepoUrl, localPath}; // 执行命令 Process process = Runtime.getRuntime().exec(cmd); // 读取命令行输出 BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); String s = null; while ((s = stdInput.readLine()) != null) { System.out.println(s); } // 等待命令执行完成 process.waitFor(); System.out.println("Git clone branch "+branch+" completed."); result = "SUCCESS"; } catch (IOException | InterruptedException e) { result = "ERROR"; e.printStackTrace(); } return result; }