DEV Community · Show DEV9/5 13:0459

一行命令运行git blame采样器,揭示代码真正归属

Who really owns this code? A git blame sampler you can run in one command

阅读原文
本文介绍了一个名为surviving-lines的Node脚本,用于通过git blame采样分析代码库中每位作者的存活代码行数。作者发现提交次数不能反映代码的实际留存情况,因此开发了此工具。该脚本无依赖,支持Node 20+,可通过npx运行,例如:npx surviving-lines --sample 5 --include '**/*.ts'。它使用git blame -w -M(可选-C)统计存活行数,并排除合并提交,支持.mailmap和采样确定性。在langchain-ai/openwiki仓库的示例运行中,0.3秒内采样了50/203个文件,归因了14,722行,显示Colin Francis占52.4%的存活行,而Brace Sproul占22.5%,尽管两者提交数相同。作者强调该工具衡量的是存活性而非代码质量或贡献价值。