我正在尝试使用以下 Java 语法来执行 Git blame 命令:
Process process = Runtime.getRuntime().exec("/usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt");
但是,当我用 Java 运行代码时,它没有给出任何结果。而且,当我尝试在终端中执行它时,它只会创建一个空的“TestGit.txt”文件,并且出现错误:fatal: Not a git repository (or any of the parent directories): .git
。
最佳答案
确保在启动命令之前将目录更改为 git 存储库
Process process = Runtime.getRuntime().exec("cd /path/to/repository; /usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt");
关于java - 在java中执行git blame命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11039517/