先說這是一般人不大會遇到的冷門問題,大家若閒來無事,可抱著長見識的心情隨喜參考。

先前處理 BRIX 迷你電腦棘手的內顯驅動崩潰,原本已裝好 Windows 11,為了驗證是否跟 Windows 版本有關,我特別刪掉 C: 槽重裝 Windows 10 (放文件、專案的 D: X: 槽則沿用),可惜最後以換新主機收場...

重裝 Windows 後,裝好 Git、VSCode、VS2022,試著開啟 X: 上的 .NET 6 專案,發現 Visual Studio 2022 的 Git 操作怪怪的,檔案圖示有已加入版控的藍色鎖頭符號,但找不到任何分支、修改檔案也不會出現在 Git Changes 清單,一整個不對勁,無法進行 Git 操作。

找了大半天也想不出為什麼,切到 Output / Source Control - Git 才看到線索:

改用 CLI 可以看到更明確的訊息:

PS D:\demo> git status
fatal: detected dubious ownership in repository at 'X:/deom'
'D:/demo' is owned by:
        'S-1-5-21-34********-*********-**********-1001'
but the current user is:
        'S-1-5-21-83*******-**********-**********-1001'
To add an exception for this directory, call:

        git config --global --add safe.directory D:/demo
PS D:\demo> 

推敲原因,專案檔時之前裝好 Windows 11 時寫入的,重裝 Windows 10 後,雖然使用者名稱我都取為 jeffrey,但其 SID 是不同的,前 Git 來說是不同的使用者,當使用者 A 開啟擁有者為使用者 B 的專案時,便會冒出「detected dubious ownership in repository」錯誤,這是 Git 2.35.2 版加入的安全修正,之前已交手過。使用 whoami /user 查詢,可證實 83**-1001 是新裝 Windows 使用者的 SID:

知道原因就好辦,將資料夾的擁有者變更為目前的使用者,收工。

心得:Visual Studio 遇 Git 錯誤時可能不會彈出錯誤訊息,只是呈現怪異行為,此時可觀察 Output / Source Control - Git Log 或使用 Git CLI 輔助判斷。


Comments

Be the first to post a comment

Post a comment