git-2-49-features

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git 2.49+ Features (2025)

Git 2.49+ 新特性(2025)

git-backfill Command (New in 2.49)

git-backfill 命令(2.49版本新增)

What: Efficiently download missing objects in partial clones using the path-walk API.
Why: Dramatically improves delta compression when fetching objects from partial clones, resulting in smaller downloads and better performance.
功能介绍: 借助path-walk API高效下载部分克隆中缺失的对象。
优势: 大幅提升从部分克隆获取对象时的增量压缩效率,实现更小的下载体积与更优性能。

Basic Usage

基础用法

bash
undefined
bash
undefined

Check if you have a partial clone

检查是否为部分克隆

git config extensions.partialClone
git config extensions.partialClone

Download missing objects in background

在后台下载缺失的对象

git backfill
git backfill

Download with custom batch size

自定义批量大小进行下载

git backfill --batch-size=1000
git backfill --batch-size=1000

Respect sparse-checkout patterns (only fetch needed files)

遵循稀疏检出规则(仅获取所需文件)

git backfill --sparse
git backfill --sparse

Check progress

查看进度

git backfill --verbose
undefined
git backfill --verbose
undefined

When to Use

适用场景

Scenario 1: After cloning with --filter=blob:none
bash
undefined
场景1:使用--filter=blob:none克隆后
bash
undefined

Clone without blobs

不克隆 blob 对象

git clone --filter=blob:none https://github.com/large/repo.git cd repo
git clone --filter=blob:none https://github.com/large/repo.git cd repo

Later, prefetch all missing objects efficiently

后续高效预取所有缺失对象

git backfill

**Scenario 2: Sparse-checkout + Partial clone**
```bash
git backfill

**场景2:稀疏检出 + 部分克隆**
```bash

Clone with both optimizations

同时启用两种优化进行克隆

git clone --filter=blob:none --sparse https://github.com/monorepo.git cd monorepo git sparse-checkout set src/api
git clone --filter=blob:none --sparse https://github.com/monorepo.git cd monorepo git sparse-checkout set src/api

Fetch only needed objects

仅获取所需对象

git backfill --sparse

**Scenario 3: CI/CD Optimization**
```bash
git backfill --sparse

**场景3:CI/CD 优化**
```bash

In CI pipeline - fetch only what's needed

在CI流水线中 - 仅获取所需内容

git clone --filter=blob:none --depth=1 repo git backfill --sparse
git clone --filter=blob:none --depth=1 repo git backfill --sparse

Much faster than full clone

比完整克隆快得多

undefined
undefined

Performance Comparison

性能对比

Traditional partial clone fetch:
bash
git fetch --unshallow
传统部分克隆获取方式:
bash
git fetch --unshallow

Downloads 500MB in random order

随机顺序下载500MB内容

Poor delta compression

增量压缩效果差


**With git-backfill:**
```bash
git backfill

**使用git-backfill:**
```bash
git backfill

Downloads 150MB with optimized delta compression (70% reduction)

通过优化增量压缩仅下载150MB(体积减少70%)

Groups objects by path for better compression

按路径分组对象以提升压缩效果

undefined
undefined

Path-Walk API (New in 2.49)

Path-Walk API(2.49版本新增)

What: Internal API that groups together objects appearing at the same path, enabling much better delta compression.
How it works: Instead of processing objects in commit order, path-walk processes them by filesystem path, allowing Git to find better delta bases.
Benefits:
  • 50-70% better compression in partial clone scenarios
  • Faster object transfers
  • Reduced network usage
  • Optimized packfile generation
You benefit automatically when using:
  • git backfill
  • git repack
    (improved in 2.49)
  • Server-side object transfers
功能介绍: 内部API,将同一路径下的对象分组,实现更优的增量压缩。
工作原理: 不再按提交顺序处理对象,而是按文件系统路径处理,让Git能找到更合适的增量基准。
优势:
  • 部分克隆场景下压缩效果提升50-70%
  • 对象传输速度更快
  • 降低网络占用
  • 优化打包文件生成
以下操作会自动受益:
  • git backfill
  • git repack
    (2.49版本已优化)
  • 服务端对象传输

Enable Path-Walk Optimizations

启用Path-Walk优化

bash
undefined
bash
undefined

For repack operations

针对重打包操作

git config pack.useBitmaps true git config pack.writeBitmaps true
git config pack.useBitmaps true git config pack.writeBitmaps true

Repack with path-walk optimizations

借助Path-Walk优化进行重打包

git repack -a -d -f
git repack -a -d -f

Check improvement

查看优化效果

git count-objects -v
undefined
git count-objects -v
undefined

Performance Improvements with zlib-ng

基于zlib-ng的性能提升

What: Git 2.49 includes improved performance through zlib-ng integration for compression/decompression.
Benefits:
  • 20-30% faster compression
  • 10-15% faster decompression
  • Lower CPU usage during pack operations
  • Transparent - no configuration needed
Automatically improves:
  • git clone
  • git fetch
  • git push
  • git gc
  • git repack
功能介绍: Git 2.49集成zlib-ng以提升压缩/解压缩性能。
优势:
  • 压缩速度提升20-30%
  • 解压缩速度提升10-15%
  • 打包操作时CPU占用更低
  • 透明化 - 无需额外配置
自动优化以下操作:
  • git clone
  • git fetch
  • git push
  • git gc
  • git repack

New Name-Hashing Algorithm

新的名称哈希算法

What: Improved algorithm for selecting object pairs during delta compression.
Results:
  • More efficient packfiles
  • Better compression ratios (5-10% improvement)
  • Faster repack operations
Automatic - no action needed.
功能介绍: 优化增量压缩过程中对象对的选择算法。
效果:
  • 打包文件更高效
  • 压缩比提升5-10%
  • 重打包操作速度更快
自动生效 - 无需手动操作。

Rust Bindings for libgit

libgit的Rust绑定

What: Git 2.49 added Rust bindings (libgit-sys and libgit-rs) for Git's internal libraries.
Relevance: Future Git tooling and performance improvements will leverage Rust for memory safety and performance.
For developers: You can now build Git tools in Rust using official bindings.
功能介绍: Git 2.49为Git内部库添加了Rust绑定(libgit-sys和libgit-rs)。
意义: 未来Git工具与性能优化将借助Rust的内存安全性与性能优势。
面向开发者: 现在可以使用官方绑定用Rust构建Git工具。

Promisor Remote Enhancements

Promisor远程仓库增强

What: Servers can now advertise promisor remote information to clients.
Benefits:
  • Better handling of large files in partial clones
  • Improved lazy fetching
  • More efficient missing object retrieval
Configuration:
bash
undefined
功能介绍: 服务器现在可以向客户端广播promisor远程仓库信息。
优势:
  • 更好地处理部分克隆中的大文件
  • 改进延迟获取机制
  • 更高效地检索缺失对象
配置方式:
bash
undefined

View promisor remote info

查看promisor远程仓库信息

git config remote.origin.promisor git config extensions.partialClone
git config remote.origin.promisor git config extensions.partialClone

Verify promisor packfiles

验证promisor打包文件

ls -lah .git/objects/pack/*.promisor
undefined
ls -lah .git/objects/pack/*.promisor
undefined

Git 2.49 Workflow Examples

Git 2.49工作流示例

Example 1: Ultra-Efficient Monorepo Clone

示例1:超高效单体仓库克隆

bash
undefined
bash
undefined

Clone large monorepo with maximum efficiency

以最高效方式克隆大型单体仓库

git clone --filter=blob:none --sparse https://github.com/company/monorepo.git cd monorepo
git clone --filter=blob:none --sparse https://github.com/company/monorepo.git cd monorepo

Only checkout your team's service

仅检出你的团队负责的服务

git sparse-checkout set --cone services/api
git sparse-checkout set --cone services/api

Fetch needed objects with path-walk optimization

借助path-walk优化获取所需对象

git backfill --sparse
git backfill --sparse

Result: 95% smaller than full clone, 70% faster download

结果:体积比完整克隆小95%,下载速度提升70%

undefined
undefined

Example 2: CI/CD Pipeline Optimization

示例2:CI/CD流水线优化

yaml
undefined
yaml
undefined

.github/workflows/ci.yml

.github/workflows/ci.yml

jobs: test: runs-on: ubuntu-latest steps: - name: Checkout with optimizations run: | git clone --filter=blob:none --depth=1 --sparse ${{ github.repositoryUrl }} cd repo git sparse-checkout set src tests git backfill --sparse
  - name: Run tests
    run: npm test
jobs: test: runs-on: ubuntu-latest steps: - name: 借助优化方式检出代码 run: | git clone --filter=blob:none --depth=1 --sparse ${{ github.repositoryUrl }} cd repo git sparse-checkout set src tests git backfill --sparse
  - name: 运行测试
    run: npm test

80% faster than full clone in CI

比完整克隆快80%

undefined
undefined

Example 3: Working with Huge History

示例3:处理超大历史仓库

bash
undefined
bash
undefined

Clone repository with massive history

克隆拥有海量历史记录的仓库

git clone --filter=blob:none https://github.com/project/with-long-history.git cd with-long-history
git clone --filter=blob:none https://github.com/project/with-long-history.git cd with-long-history

Work on recent code only (objects fetched on demand)

仅处理近期代码(按需获取对象)

git checkout -b feature/new-feature
git checkout -b feature/new-feature

When you need full history

当需要完整历史时

git backfill
git backfill

Repack for optimal storage

重打包以优化存储

git repack -a -d -f # Uses path-walk API
undefined
git repack -a -d -f # 借助path-walk API
undefined

Deprecated Features (Removal in Git 3.0)

已废弃特性(将在Git 3.0移除)

⚠️ Now Officially Deprecated:
  • .git/branches/
    directory (use remotes instead)
  • .git/remotes/
    directory (use git remote commands)
Migration:
bash
undefined
⚠️ 现已正式废弃:
  • .git/branches/
    目录(改用远程仓库)
  • .git/remotes/
    目录(改用git remote命令)
迁移方式:
bash
undefined

If you have old-style remotes, convert them

如果你有旧版远程仓库配置,进行转换

Check for deprecated directories

检查废弃目录

ls -la .git/branches .git/remotes 2>/dev/null
ls -la .git/branches .git/remotes 2>/dev/null

Use modern remote configuration

使用现代远程仓库配置

git remote add origin https://github.com/user/repo.git git config remote.origin.fetch '+refs/heads/:refs/remotes/origin/'
undefined
git remote add origin https://github.com/user/repo.git git config remote.origin.fetch '+refs/heads/:refs/remotes/origin/'
undefined

Meson Build System

Meson构建系统

What: Continued development on Meson as alternative build system for Git.
Why: Faster builds, better cross-platform support.
Status: Experimental - use
make
for production.
功能介绍: 持续开发Meson作为Git的替代构建系统。
原因: 构建速度更快,跨平台支持更好。
状态: 实验性阶段 - 生产环境请使用
make

netrc Support Re-enabled

重新启用netrc支持

What: HTTP transport now supports .netrc for authentication.
Usage:
bash
undefined
功能介绍: HTTP传输现在支持通过.netrc进行身份验证。
使用方式:
bash
undefined

~/.netrc

~/.netrc

machine github.com login your-username password your-token
machine github.com login your-username password your-token

Git will now use these credentials automatically

Git现在会自动使用这些凭据

Best Practices with Git 2.49

Git 2.49最佳实践

  1. Use git-backfill for partial clones:
    bash
    git backfill --sparse  # Better than git fetch --unshallow
  2. Combine optimizations:
    bash
    git clone --filter=blob:none --sparse <url>
    git sparse-checkout set --cone <paths>
    git backfill --sparse
  3. Regular maintenance:
    bash
    git backfill  # Fill in missing objects
    git repack -a -d -f  # Optimize with path-walk
    git prune  # Clean up
  4. Monitor partial clone status:
    bash
    # Check promisor remotes
    git config extensions.partialClone
    
    # List missing objects
    git rev-list --objects --all --missing=print | grep "^?"
  5. Migrate deprecated features:
    bash
    # Move away from .git/branches and .git/remotes
    # Use git remote commands instead
  1. 对部分克隆使用git-backfill:
    bash
    git backfill --sparse  # 比git fetch --unshallow更优
  2. 组合多种优化:
    bash
    git clone --filter=blob:none --sparse <url>
    git sparse-checkout set --cone <paths>
    git backfill --sparse
  3. 定期维护:
    bash
    git backfill  # 补全缺失对象
    git repack -a -d -f  # 借助path-walk优化
    git prune  # 清理无用内容
  4. 监控部分克隆状态:
    bash
    # 检查promisor远程仓库
    git config extensions.partialClone
    
    # 列出缺失对象
    git rev-list --objects --all --missing=print | grep "^?"
  5. 迁移废弃特性:
    bash
    # 不再使用.git/branches和.git/remotes
    # 改用git remote命令

Troubleshooting

故障排查

git-backfill not found:
bash
undefined
找不到git-backfill:
bash
undefined

Verify Git version

验证Git版本

git --version # Must be 2.49+
git --version # 必须为2.49+

Update Git

更新Git

brew upgrade git # macOS apt update && apt install git # Ubuntu

**Promisor remote issues:**
```bash
brew upgrade git # macOS apt update && apt install git # Ubuntu

**Promisor远程仓库问题:**
```bash

Reset promisor configuration

重置promisor配置

git config --unset extensions.partialClone git config --unset remote.origin.promisor
git config --unset extensions.partialClone git config --unset remote.origin.promisor

Re-enable

重新启用

git config extensions.partialClone origin git config remote.origin.promisor true

**Poor delta compression:**
```bash
git config extensions.partialClone origin git config remote.origin.promisor true

**增量压缩效果差:**
```bash

Force repack with path-walk optimization

强制使用path-walk优化进行重打包

git repack -a -d -f --depth=250 --window=250
undefined
git repack -a -d -f --depth=250 --window=250
undefined

Resources

参考资源