0
2

More than 1 year has passed since last update.

ソース管理からGit操作ができないときは

Posted at

はじめに

Windows 10からWindows 11にアップグレードしようとするも10回くらい失敗したのでクリーンインストールしました。
それにともなってVSCodeやらGitをインストールしました。

なんと以前のワークスペースをVSCodeで開くと、ソース管理に「リポジトリを初期化する」というボタンが表示されているではありませんか。
ターミナルからgitコマンドは呼べるからインストールは問題ないようだし、VSCodeの設定で直接git.exeの実行ファイルのパスを指定しても変わらないのはなぜなんでしょう?

VSCodeがGitリポジトリを認識しなくなった!

その原因はGitのバージョンアップによるものかもしれません。

どうやらGit 2.30.3CVE-2022-24765という問題に対応する変更が加えられ、Git 2.35.2以降のバージョンで適用されているようです。

ターミナルでgit statusと実行すると

fatal: detected dubious ownership in repository at 'path/to/repository'
'path/to/repository' is owned by:
        'owner-user-id'
but the current user is:
        'current-user-id'
To add an exception for this directory, call:

        git config --global --add safe.directory path/to/repository

と表示されました。
指示通り

git config --global --add safe.directory path/to/repository

を実行して、ワークスペースを読み込みなおすとうまくいきます。

その他

上記の方法はVSCodeでワークスペースを信頼するように、Gitのconfigに信頼するディレクトリを追加するものです。
追加したディレクトリ一覧を確認したり編集したりする場合は

git config --global -e

でconfigを編集するといいでしょう。

configに値を書き込みたくない場合、

takeown /r /s pcname /u username /f path/to/repository

と実行して所有者を変え、警告を回避する方法もあるようです。

参照

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2