java - 在java中执行git blame命令

标签 java linux git github

我正在尝试使用以下 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/

相关文章:

Java CMS GC 行为

c - 它正在录制,但录制的视频无法播放。它给出错误 "moov data not found",请帮我解决这个问题

linux - 将 'sed' 到 'spawn' 执行到预期脚本中

Git pull 很慢……为什么?

java - 我可以定义自己的 java.util.List 子类吗?

java - Hadoop 命令不从 java prcoessbuilder 执行

java - 必需的: variable Found:value Error Java Text-Based Calculator

c - Linux 上的 IOCTL_STORAGE_QUERY_PROPERTY 相当于什么?

linux - git:编辑文件导致使用 git diff 时出现 ^M

git - 如何将 redmine 用户与存储库用户链接起来