更新更改时出错:不安全的存储库 ... 归其他人所有

Error updating changes: unsafe repository ... is owned by someone else

最近当我在 Android Studio 中打开 git 项目时,我收到此错误:

Error updating changes: Unsafe repository (`project name` is owned by someone else). To add an exception to this directory, call : git config --global --add safe.directory ...

我知道使用提到的命令行可以解决这个问题,但是没有任何自动解决方案吗?

我有很多项目,时不时地遇到这个问题!

首先检查您的 Git 版本:

git version

如果是最近的2.35.2或者2.36,需要设置safe.directory setting, because of CVE-2022-24765.

git config --global --add safe.directory 'Path/To/Repo'

或者你can disable it, but make sure you understand why it is there in the first place.