沙箱环境下的 git 安全操作与仓库恢复
FreeNo executable scriptsNot checked在 WorkBuddy 的沙箱环境里安全地对 git 仓库做 fetch/push/rebase,并在 .git 丢失、origin/main 不存在、push 被拒时按固定流程恢复。当出现「git rebase 失败」「.git 不见了」「not a git repository」「origin/main 不存在…
by oracis462 installs in other catalogsAbout this skill
沙箱环境下的 git 安全操作与仓库恢复
0. 先判断:目标仓库在会话工作区里吗?
WorkBuddy 的 Bash 工具跑在沙箱里,写权限默认只覆盖当前会话工作区,
再叠加 ~/.workbuddy/settings.json 里的白名单:
{ "sandbox": { "extraAllowWrite": ["~/AppData/Local/AgentConnectors/", "..."] } }
如果项目目录既不等于会话工作区、也不在白名单里,git 的部分写操作会静默失效。 先确认一次:
git rev-parse --show-toplevel # 项目根
# 与会话工作区(系统提示里的 Workspace Folder)比对
- 推荐做法:把项目目录加进
sandbox.extraAllowWrite,或改用会话工作区内的副本操作。 - 下面的症状都是「不在白名单」时实测遇到的,先记住两条铁律:
- 不要在非白名单目录里跑
git rebase(见 §2,实测把整个.git弄没了)。 - 任何「改了但 status 没变」的情况,先怀疑写入被沙箱丢了,而不是 git 逻辑。
- 不要在非白名单目录里跑
1. 症状 → 原因对照
| 症状 | 实测原因 / 处置 |
|---|---|
git fetch origin main 打印 * [new branch] main -> origin/main,但随后 git rev-parse origin/main 报 unknown revision、git show-ref 里只有 refs/heads/main |
.git/refs/remotes/** 下 git 的「锁文件 + rename」写入被沙箱吃掉。按 §3 用 python 直写这个引用文件即可 |
git update-ref refs/remotes/origin/main <sha> 返回 0 却仍然没有该引用 |
同上,update-ref 也走 rename。不要反复重试,直接直写文件 |
git status -sb 显示 ## main...origin/main [gone] |
上一条的后果,跟踪引用丢了(分支的上游配置可能还在) |
git push 报 ! [rejected] ... (fetch first) |
远端确实有新提交(例如 GitHub Actions 的每日采集提交)。不要用 git pull --rebase,走 §4 |
git rebase <sha> 报 error: could not mark as interactive: No such file or directory |
沙箱下 rebase 要建 .git/rebase-* 目录,创建失败;紧接着 .git 会被整个删掉(实测,见 §2) |
git log 突然报 fatal: not a git repository |
上一条的后果,进入 §5 恢复流程 |
git push 报 could not read Username ... terminal prompts disabled |
全局 credential.https://github.com.helper=!gh auth git-credential 生效,但 gh auth status 是「未登录」。先按 §8 用标准接口取现成 token;找不到再回落 git config credential.https://github.com.helper store |
gh auth status 说未登录,但本机 git 凭据体系(credential helper)里存着可用 token |
用 git credential fill 标准接口取回,别去麻烦用户。见 §8 |
git branch --set-upstream-to=origin/master 报 the requested upstream branch does not exist,但 FETCH_HEAD 里明明有那个 sha |
refs/remotes/** 写入被沙箱吃掉(同 §3)。注意:此时 .git/refs/remotes/ 目录可能压根没被创建,ls 报 ENOENT。按 §3 直写即可;FETCH_HEAD 的 sha == 本地 HEAD 就能判定 push 已成功 |
git -c http.proxy= -c https.proxy= fetch origin main 成功,但同参数 push 报 Recv failure: Connection was reset |
下载走直连可以、上传必须走代理。见 §7 换 socks5:// |
同参数 push 不报错也不结束(挂住,4 分钟无任何输出,直到被杀) |
与上一条同源:上传方向直连走不通,且这次是静默挂起而不是 Recv failure。见 §7 —— 别等,直接换 socks5:// |
push 报 ! [remote rejected] main -> main (refusing to allow an OAuth App to create or update workflow '.github/workflows/xxx.yml' without 'workflow' scope) |
token 缺 workflow scope。改走 SSH(不受 OAuth scope 限制),见 §9 —— 不要去求用户换 token |
带全局 http.proxy=http://127.0.0.1:10808 push 报 TLS connect error: error:0A000126:SSL routines::unexpected eof while reading |
该端口是 SOCKS5/HTTP 双栈,但 git 用 http:// 前缀连它会在 TLS 握手时被掐。见 §7 改 socks5:// |
push 明明返回成功日志,但随后 git status -sb 又变成 [gone]、git show-ref 少了 refs/remotes/origin/main |
push 过程又把跟踪引用写丢了。按 §3 直写,注意这次要写 push 之后 的新 sha(不是 push 前的) |
head / tail / grep / sed / cat / env / tr / dirname / wc / xargs 报 command not found,且每条命令都附带 shell-runtime-bash-env.sh: line 3: dirname: command not found + cd: null directory |
PATH 缺 MSYS 目录(不是 shell 残缺)。一句话就能修好,见 §1.1 —— 不要退回 python 硬凑 |
ls / find / curl / tar 反而能用 |
它们是从 Windows PATH 命中的(C:\Program Files\OpenSSH\bin\ls、C:\Windows\System32\find/curl/tar),跟 MSYS 无关 |
1.1 PATH 缺 MSYS 目录(coreutils 集体失踪)的定位与修复
症状:grep/sed/head/tr/wc/dirname/xargs 全部 command not found;
每条命令的 stderr 都会多出 shell-runtime-bash-env.sh: line 3: dirname: command not found。
根因:Bash 工具的 PATH 是 注入前缀 + Windows PATH,没有把 MSYS 目录放进去
(shell 快照里明明有 /bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin,但没作用到 Bash 工具进程)。
于是 MSYS 的 dirname 找不到 → BASH_ENV 里的 shim 第 3 行 cd "$(dirname ...)" 失败 →
连 safe-delete-bash-env.sh / brokered-sandbox-bash-env.sh 也一并没挂上。
定位(三条命令):
echo "$PATH" # 看有没有 /usr/bin、/mingw64/bin
echo "$EXEPATH" # MSYS 根 = 它的父目录
ls "$(dirname "$EXEPATH")/usr/bin" # 或 ls "C:/.../PortableGit/versions/<ver>/usr/bin"
usr/bin 里 grep.exe / sed.exe / head.exe / dirname.exe 齐全 ⇒ 工具没坏,纯粹是 PATH 的问题。
一行修复(本会话立即可用):
export PATH="/usr/bin:/bin:/mingw64/bin:$PATH"
grep --version && git --version # 期望 grep 3.0 / git 2.55.0(来自 mingw64)
是否持久:不持久 —— Bash 工具每次调用都是新 shell。要么每条命令都带上上面那句,
要么做永久修复:把下面两条加到 PATH(机器级或用户级都行,放末尾,避免盖住系统 find/curl),
然后完全退出并重启 WorkBuddy(Bash 工具继承的是应用启动时的环境块):
C:\Users\DELL\.workbuddy\binaries\PortableGit\versions\<ver>\usr\bin
C:\Users\DELL\.workbuddy\binaries\PortableGit\versions\<ver>\mingw64\bin
改 PATH 的三个坑(2026-09-13 实测):
- Windows 形式的注册表条目有效:MSYS 在进程启动时把
C:\WINDOWS\system32转成/c/WINDOWS/system32(实测find就是这么命中的),所以写C:\...\usr\bin没问题。 但运行时export PATH='C:\...\usr\bin'无效 —— MSYS 只在启动时转换, drive-letter 形式塞进去command -v grep仍为空。临时修复必须用 POSIX 形式。
Install 沙箱环境下的 git 安全操作与仓库恢复 in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the 沙箱环境下的 git 安全操作与仓库恢复 skill do?
在 WorkBuddy 的沙箱环境里安全地对 git 仓库做 fetch/push/rebase,并在 .git 丢失、origin/main 不存在、push 被拒时按固定流程恢复。当出现「git rebase 失败」「.git 不见了」「not a git repository」「origin/main 不存在 / show-ref 里没有」「fetch 说更新了但 status 还是 gone」「push 被拒 fetch first」「could not read Username」「grep/sed/head/dirname 报 command not found」「shell-runtime-bash-env.sh: line 3: dirname: command not found」时使用。
How do I install the 沙箱环境下的 git 安全操作与仓库恢复 skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the 沙箱环境下的 git 安全操作与仓库恢复 skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
by Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
by Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropic