execute git blame command in java

I’m trying to use the following Java syntax to execute a Git blame command:

Process process = Runtime.getRuntime().exec("/usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt");

But, when I run the code in Java, it doesn’t give any result. And, when I tried to execute it in the Terminal, it just creates an empty “TestGit.txt” file, and I got the error: fatal: Not a git repository (or any of the parent directories): .git.

  • How to close/copy a specific git branch contents to a folder on another server using ssh
  • Force just one file as binary in GIT
  • Sphinx generated html pages look different when pulled to a NAS drive git repository
  • How to modify shell to show git branch one is in, if applicable
  • Squashing first and third commits (leaving second unsquashed)
  • git trying to write a file on a push that was deleted
  • Rename local GIT branch breaks Git Flow in SourceTree
  • Link to existing github repository
  • SSH agent forwarding configured and (seems to be) working but github still asks for user & password
  • Site dead. “ACTION REQUIRED: Rails Security Vulnerability ”
  • Explanation of “overwrting local changes” warning when switching branch in git in this scenario?
  • Configure the git commit used for Change Markers
  • 4 Solutions collect form web for “execute git blame command in java”

    Be sure to change directories into the git repository prior to launching the command

    Process process = Runtime.getRuntime().exec("cd /path/to/repository; /usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt");
    

    I think for git blame to work, you’ll need to be inside the repository. You’d need to be inside the repository directory (which means you’ll need to check it out first), and run:

    git blame alloc.c
    

    The following is the right syntax to execute blame command in Java for linux:

    git --git-dir=/home/gh/git/.git --work-tree=/home/gh/git blame builtin/tag.c
    

    The javier way:

    Process process = Runtime.getRuntime().exec("/usr/bin/git blame https://github.com/git/git/alloc.c > TestGit.txt", null, new File('/path/to/repository'));
    
    Git Baby is a git and github fan, let's start git clone.