You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Sneaker Net在Git仓库间导出本地提交的变更集?

Alright, let's walk through exactly how to move those 4-5 commits from your air-gapped system to another repo using Sneaker Net (good old physical media like a USB drive). This is a super common scenario when dealing with isolated environments—here's the step-by-step breakdown:

Step 1: Pin down the commits you need to export

First, figure out the exact range of commits you want to move. Run git log --oneline in your local repo on the isolated system to get the short commit hashes. For example, if you need the last 5 commits, you'll use HEAD~5..HEAD as your range. If you have specific start and end commits, use <start-hash>..<end-hash> instead.

Step 2: Export the commits for transfer

You have two solid options here, depending on whether you want individual commit files or a single bundled file:

Option 1: Generate individual patch files (great for small commit sets)

Use git format-patch to create a separate .patch file for each commit—this preserves all commit metadata (author, message, timestamps) and makes it easy to review changes before importing:

  • For the last 4 commits: git format-patch -4 HEAD
  • For a specific range: git format-patch abc123..def456
    This will spit out files like 0001-Fix-login-validation.patch and 0002-Add-reporting-feature.patch—one per commit.

Option 2: Create a single Git bundle (cleaner for larger sets)

If you prefer a single file to transfer, use git bundle to package all the commits into one bundle:
git bundle create my-isolated-changes.bundle HEAD~5..HEAD
This bundle acts like a mini repo snapshot containing only the commits you specified.

Step 3: Move the files via Sneaker Net

Copy the .patch files or .bundle file onto a USB drive (or any physical media you can bring across the isolation barrier) and take it to the environment with your target Git repo.

Step 4: Import the commits into the target repo

Now, apply the changes to your destination repo—pick the method that matches how you exported:

If you used patch files:

Navigate to your target repo and run git am to apply all the patches in order:
git am /path/to/your/patches/*.patch
If you run into conflicts (which can happen if the target repo has diverged), Git will pause the process. Fix the conflicts in the affected files, then run git am --continue to finish applying the patches. If you need to abort, use git am --abort.

If you used a Git bundle:

First, verify the bundle is valid (this checks that the target repo has all the necessary parent commits):
git bundle verify my-isolated-changes.bundle
Then import the commits. If you want to pull them directly into your current branch:
git pull my-isolated-changes.bundle
Or if you want to import them into a new branch:
git fetch my-isolated-changes.bundle refs/heads/your-isolated-branch:new-local-branch

Quick tips to avoid headaches

  • Make sure the target repo has the exact parent commit that your exported commits are based on. If not, you'll get conflicts or errors—you might need to expand your export range to include any missing dependencies.
  • For small commit sets (like your 4-5), patches are usually easier to troubleshoot if something goes wrong, since you can apply them one at a time.
  • Always double-check the commits with git log after importing to make sure everything transferred correctly.

内容的提问来源于stack exchange,提问作者Rich Shealer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:10:32