惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

野小新 – 魔帆博客

Python包管理的血泪史:从混乱到秩序的漫长征 | 魔帆博客 Mac mini + iPad 随航梦幻联动!零显示器配置指南,iPad 秒变 Mac 主屏幕 | 魔帆博客 解锁iOS侧载自由:使用sideStore轻松搞定ipa签名 | 魔帆博客 Git配置:如何优雅的配置多用户并使用 ssh 密钥验证 | 魔帆博客 Git 合并本地两个不同的 Repo 仓库 | 魔帆博客 安装有 RootMagiskXposedPlay 的 WSA 安卓子系统 | 魔帆博客 Fedora 系统升级 32->34 跨版本升级 | 魔帆博客 教程:如何更新安装 docker-compose V2 和使用 docker switch | 魔帆博客 2022 年 Android 下的安卓浏览器使用指北-Firefox向 | 魔帆博客 Docker WSL1/2 迁移 Linux 发行版目录 | 魔帆博客 Spotify 主题 spicetify-fluent - 微软 win11 风格美化 | 魔帆博客 WSA 安卓子系统 adb 提示 cannot connect the target machine actively refused it 10061 | 魔帆博客 双重验证 Authy 导出所有 TOTP token 和 golang 配置 GOPROXY 解决网络问题 | 魔帆博客 powershll 像 bash 一样为单个命令设置临时环境变量 | 魔帆博客 Linux 教程:Linux 初学者必了解的概念 | 魔帆博客 安卓电池充电保护-智能充电/温控切断(Root方案) | 魔帆博客 备用机养成方案 - Tasker 安卓短信转发到 telegram | 魔帆博客 创建支持安全启动(Secure Boot)的 Arch Linux ISO 安装镜像 | 魔帆博客 MiBand小米手环2/3刷机刷固件刷表盘刷字体指南(iPhone iOS 也支持) | 魔帆博客
Git 提示 fatal: unsafe repository is owned by someone else 错误 | 魔帆博客
野小新 · 2022-04-26 · via 野小新 – 魔帆博客

最近在使用 Git 和 GitHub Actions 时,应该不少人都遇到了这个问题:

fatal: unsafe repository ('D:/Paxos/scoop/buckets/MorFans' is owned by someone else)
To add an exception for this directory, call:

        git config --global --add safe.directory D:/Paxos/scoop/buckets/MorFans

解决

这个问题可能和 Git安全漏洞公布| GitHub 博客 有关,应该只发生于最近更新的 git 程序

解决方案也很简单,因为这个报错是因为当前目录所有者不是当前操作系统的用户。

下面介绍两种方法解决这个问题:

  1. 修改文件所有者
  2. 添加安全目录

修改文件所有者

Windows 修改所有者方法

如果习惯使用命令行,可以使用 takeown.exe 快速设定所有者为当前用户:

takeown.exe /F .\nonportable /R

命令行批量处理:

Get-ChildItem -Directory | % {takeown.exe /F $_ /R }

或者使用图形界面修改:

找到 git repo 的文件夹,右键点击属性:

3967533be19f476f98ee2daa3bcf6240
右键进入git repo 的文件夹属性

找到 安全,点击高级设置:

dae9ee6aa2434f24bca2b0c9ff527712
进入权限设置

在弹出的窗口点击更改,输入自己电脑的用户名:

f5c49d88abbe4883a4d01d15c4940586
修改当前所有者用户
9e1514d625354a8480b32507626db4b3
按照图示操作然后应用设置

Linux 等Unix系系统修改所有者方法

# paxos:morfans => 用户名:组
sudo chown -R paxos:morfans  gitRepo文件夹路径

还可以通过指定 git 的用户身份运行

假设 morfans 是存储库所有者

sudo -u morfans -- git status

添加 git 安全目录

第二个方法就是 git 命令报错时候提示的方法。

如果你是在 GitHub Actions 中遇到这个问题,可能添加 safe.directory 是更方便的选择。

让 git 信任这个目录(如果您知道目录内容是安全的)

git config --global --add safe.directory <Git Repo文件夹路径>

或者手动调整 git 配置文件 C:\Users\<username>\.gitconfig

[safe]
    directory = gitRepo文件夹路径

repo太多了,批量来

Linux 下可以使用 find 命令来批量执行:

如果子目录太多了,可以使用 -maxdepth 参数

find 完整路径 -name '.git' -type d -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;

Windows 下可以使用 powershell 批量执行:

(ls D:\PowerShell\ParentFolder\ -Directory).FullName -replace '\\','/' | %{git config --global --add safe.directory $_}

虽然但是 👀,还是推荐修改文件夹权限,而不是添加 安全文件夹