user1153395
user1153395

Reputation: 87

Android Studio GIT error when trying to annotate

When I right click on the side and click "Annotate" I get the following error

Error:Failed to annotate: com.intellij.openapi.vcs.VcsException: fatal: no such path app/src/main/java/.. ../MainActivity.java in HEAD during executing git -c core.quotepath=false blame --porcelain -l -t -w HEAD -- app/src/main/java/.. ../MainActivity.java

Google didnt help. I tried cloning the repo again but didnt work. I have no idea whats going on.

Also when I try to look at the history, the console says something like

fatal: no such path .../MainActivity.java in HEAD

Upvotes: 4

Views: 1851

Answers (3)

auspicious99
auspicious99

Reputation: 4311

(tested with Android Studio Jellyfish, Dec 2024)

In my case, it seems that for whatever reason (such as I was working on an old, slow Mac on MacOS Catalina), Android Studio did not find the git location upon starting up, then when I tried to do things like git blame (to annotate with git), or show git log from the Git menu, it failed. git blame did nothing at all, and showed nothing. show git log showed the empty UI where normally it would show the git log.

However, I went to Preferences -> Version Control -> Git and saw that Android Studio had in fact found the location of the git executable on this machine, as seen in this screenshot. path to git executable

Anyway, I clicked "Test", and it changed to the following, actually finding the version of git (besides the path) and displaying it. enter image description here

For whatever reason, that appeared to do the trick. I went away for some coffee, and when I came back, git was working fine, including git blame, show git log, and so on.

Upvotes: 0

Mete
Mete

Reputation: 5625

I struggled for months with this happening but just for Git submodule code - and in my case the "Oh you renamed your folders" solutions didn't help me at all.

Finally this was the solution for my case:

  1. Go to Android Studio Preferences, Version Control tab
  2. Under the Directory list, add in all the submodule root folders (you may find they are already there but under an "Unregistered" header in the list - in that case you can simply select those and hit the + button, bottom left, to add them.)

That's it, fixed my annotate and git change highlighting issues.

Upvotes: 6

Ken Ratanachai S.
Ken Ratanachai S.

Reputation: 3547

The OP got it resolved now, but I am answering this for who came across this problem like I just did.

The paths in git repo are case-sensitive. So try to rename your folder in git to match the checkout folder on your system, especially if you are on Mac/Linux. Try run annotate again should work now.

git mv FOO foo2
git mv foo2 foo
git commit -m "Fix case sensitivity"

Upvotes: 2

Related Questions