LoginSignup
1
0

More than 1 year has passed since last update.

VS Codeでgitのリポジトリが表示されない

Posted at

TL;DR

Ctlr+Shift+U(macはShift+Cmd+U)を押して、出力ペインからGitを選択して表示されているsafe.directory設定を行うんだ…!

git config --global --add safe.directory c:/git_repos/repo_dir

Visual_Studio_Code-2.png

想定している状態

PCをクリーンインストールまたは新しく買ってきた場合、ホームディレクトリ内に.gitconfigファイルがなく、VS CodeのGit自動実行時にカレントディレクトリがセーフディレクトリ指定されていないことがあります。
VS Codeで.gitディレクトリが含まれるディレクトリを開いてもリポジトリがあると認識してもらえません。

このとき、VS Codeの出力ペインのGitの出力を見ると、次のような出力が確認できます。

[2022-09-07T22:49:11.156Z] fatal: detected dubious ownership in repository at 'C:/git_repos/repo_dir'
To add an exception for this directory, call:

	git config --global --add safe.directory C:/git_repos/repo_dir

対処法

素直に出力に表示されているコマンドを実行します。その後、VS Codeを閉じて起動し直すとセーフディレクトリ設定が反映され、リポジトリとして認識されます。

git config --global --add safe.directory C:/git_repos/repo_dir

設定の確認

ホームディレクトリにある.gitconfigに、セーフディレクトリ登録したリストが表示されているのでそれを目視できます。

~/.gitconfig
[user]
	name = your_user_name  # git config --global user.name で表示されるもの 
	email = 12345678+your_user_name@users.noreply.github.com  # git config --global user.email で表示されるもの
[safe]
	directory = C:/git_repos/repo_dir     # さっきのコマンドで登録したもの
    directory = ...                       # 登録した数だけ列挙される

ちなみに、コマンドを実行しなくてもこの~/.gitconfig[safe]以下をエディタで編集してもセーフディレクトリ設定は有効になります。

参考リンク

1
0
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
1
0