修复 Apple Silicon 下 Sublime Merge 无法使用 git-lfs

问题

  • git 库里面设置 git-lfs 后,如果在 sublime merge 里面提交修改,出现报错:
1
2
git-lfs filter-process: git-lfs: command not found
fatal: the remote end hung up unexpectedly

愚蠢的人类尝试

  • LFS not working on Apple Silicon with Monterey · Issue #1438 · sublimehq/sublime_merge (github.com)wandering-tales 的回复,找到问题发生原因:Mac 上的 git 是通过 Xcode 命令行工具安装的,git-lfs 是通过 HomeBrew 安装的,两个软件安装位置不同会引起冲突。
  • 解决方法
    • 利用 HomeBrew 安装一个 git
    • 配置一下 PATH,保证最终 which git 指向的地址是 /opt/homebrew/bin/git
  • 网上看了半天,没有找到可以用的方法,自己尝试修改 .git/hooks/pre-push 文件
    • 修改前, command 这一行就是检测有没有安装 git-lfs
1
2
3
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs pre-push "$@"
+ 修改后,手动加上 `git-lfs` 所在的路径
1
2
3
4
#!/bin/sh
export PATH=$PATH:/opt/homebrew/bin/
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; }
git lfs pre-push "$@"
  • 问题执行 git/hooks 下面脚本,用的 shell 是 bin/sh,找不到 git-lfs,不知道怎么修改?

Kimi For Coding + Claude Code

  • 问题原因:Git LFS 已安装在 /opt/homebrew/bin/git-lfs,但 Sublime Merge 是 GUI 应用,它默认的 PATH 不包含 Homebrew 路径。
  • 解决方法: 配置 Git 使用绝对路径(永久解决)
1
2
3
git config --global filter.lfs.process '/opt/homebrew/bin/git-lfs filter-process'
git config --global filter.lfs.smudge '/opt/homebrew/bin/git-lfs smudge -- %f'
git config --global filter.lfs.clean '/opt/homebrew/bin/git-lfs clean -- %f'

网络回响

修复 Apple Silicon 下 Sublime Merge 无法使用 git-lfs

https://blog.xiang578.com/post/logseq/35359.html

作者

Ryen Xiang

发布于

2024-05-03

更新于

2026-02-17

许可协议


评论