Bun v1.1.39 引入了 bun.lock,一个 JSONC 格式的锁文件。bun.lock 是人类可读且无需配置即可 git diff 的,同时不影响性能。 了解更多。
为了让 git 能够生成 Bun 二进制锁文件格式 (.lockb) 的人类可读 diff,请将以下内容添加到你的本地或全局 .gitattributes 文件中
*.lockb binary diff=lockb
然后使用以下命令将以下内容添加到你的本地 git 配置中
git config diff.lockb.textconv bungit config diff.lockb.binary true要全局配置 git 以 diff Bun 的锁文件,请使用以下命令将以下内容添加到你的全局 git 配置中
git config --global diff.lockb.textconv bungit config --global diff.lockb.binary true工作原理
为什么这样可行
textconv告诉 git 在 diff 文件之前运行 bunbinary告诉 git 将文件视为二进制文件(因此它不会尝试逐行 diff)
在 Bun 中,你可以执行 Bun 的锁文件 (bun ./bun.lockb) 来生成锁文件的可读版本,而 git diff 随后可以使用该版本生成人类可读的 diff。