Git4Idea: GitHistoryUtils.history() with "--follow" parameter leads to VcsException bad revision

Answered

I'd like to run the command git log HEAD --follow <file> to see what commits touch a specific file on the current head. So I tried running:

List<GitCommit> listOfCommits = GitHistoryUtils.history(
myProject,
myGitRepository.getRoot(),
GitUtil.HEAD,
"--follow",
"file1.txt"
);

However, by doing so, I get the VcsException com.intellij.openapi.vcs.VcsException: bad revision 'file1.txt'. (I can confirm that this works in the command line).

Is it possible to get this to work using GitHistoryUtils.history()?

Update: I just realized that this also occurs if I run without the --follow parameter.

0
3 comments
Official comment

Hi, sworden. For commits touching a specific file you can look at "git4idea.history.GitFileHistory#loadHistory" and "git4idea.history.GitFileHistory#collectHistory", and there is also "git4idea.history.GitFileHistory#collectHistoryForRevision". "GitHistoryUtils#history" does not support file paths parameters so it won't suit your needs.

You might want to try 'git log HEAD --follow -- file.txt' to avoid parameter ambiguity.

0

Hi Aleksey, thanks for the advice. Unfortunately, by doing this I get com.intellij.openapi.vcs.VcsException: --follow requires exactly one pathspec.

I got this by running:

List<GitCommit> listOfCommits =
GitHistoryUtils.history(myProject,
myGitRepository.getRoot(),
GitUtil.HEAD,
"--follow",
"--",
"file1.txt");

I even tried to do this just to see if it would resolve the issue, but still the same problem:

List<GitCommit> listOfCommits =
GitHistoryUtils.history(myProject,
myGitRepository.getRoot(),
GitUtil.HEAD,
"--follow",
"-- file1.txt");
0

Please sign in to leave a comment.