问题
I am more familiar with using git on the command line (MacOS, especially). However, I sometimes try to use the Android Studio VCS "commit", as it is sometimes slightly faster to use. The weird problem that I came across today is that Android's Studio git "commit" does not see my 4 modified files, whereas from the command line, git status
shows clearly the 4 modified files. I have seen this Stack Overflow post and I have checked it is not for any of these reasons (like, not adding the file to the git repository, or it is stashed, etc,). Besides, since git status
shows the files, they are clearly in the repo, they are not stashed, and they are modified.
Here are the screenshots from Android Studio and from the command line showing the discrepancy.
Some other things I checked:
- The project path in Android Studio matches with the path on the command line. (so I'm not looking at a different copy of the git repo)
- My .gitignore is not excluding those 4 modified files. In any case, even if it is, it should be doing that for both the command line git and the Android Studio git, right?
- The "path to Git executable" setting in Android Studio is
/usr/bin/git
, same as what I get withwhich git
from the command line.
Any ideas what may be the problem?
ps. I may have encountered such a problem before, and just proceeded to use the command line. But this time, I hope to learn something new about the Android Studio git integration :-).
回答1:
The problem turned out to be that I had two git roots listed in my Android Studio settings (Preferences->Version Control in MacOS). Not sure how that happened. For this project, my git repo root has two subfolders, and the android project is in one of those two folders. Somehow, Android Studio had added the subfolder with the android project as another git root (see the screenshot with the 2 git roots). Or maybe it was trying to be clever and suggested that I add that subfolder as a git root, and I carelessly clicked "ok".
So, I removed the git root that pointed to my android project. Then it looks like this,
And now, git integration in Android Studio is working properly again.
Just in case this happens to anyone else in the future, check your Android Studio git roots (and path to Git executable too, at Preferences->Version Control->Git).
来源:https://stackoverflow.com/questions/61725690/android-studios-git-commit-not-seeing-my-modified-files