Skip to main content

Documentation Index

Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt

Use this file to discover all available pages before exploring further.

Bun v1.1.39 引入了 bun.lock,一种 JSONC 格式的锁文件。bun.lock 是可读的且无需配置即可被 git diff,比对时对性能无影响。在 1.2.0 及以上版本中,它是新项目默认使用的格式。 了解更多。

要教会 git 如何针对 Bun 的二进制锁文件格式(.lockb)生成可读的差异,请将以下内容添加到你的本地或全局 .gitattributes 文件中:
gitattributes
*.lockb binary diff=lockb

然后通过以下命令将内容添加到本地 git 配置中:
terminal
git config diff.lockb.textconv bun
git config diff.lockb.binary true

若要全局配置 git 比较 Bun 的锁文件,请使用以下命令添加到全局 git 配置:
terminal
git config --global diff.lockb.textconv bun
git config --global diff.lockb.binary true

工作原理

为何这样设置生效:
  • textconv 告诉 git 在进行差异比较前先运行 bun 来处理文件
  • binary 告诉 git 将该文件视作二进制(避免逐行比较)
在 Bun 中,你可以执行 Bun 的锁文件(bun ./bun.lockb)来生成该锁文件的可读版本,git diff 随后即可利用此实现可读的差异比较。