Appearance
git fast-import / fast-export — quick reference
Export
| Task | Command |
|---|---|
| Full repo | git fast-export --all > repo.stream |
| Last N commits | git fast-export HEAD~N..HEAD > repo.stream |
| Single branch | git fast-export --branches main > repo.stream |
| Path-filtered | git fast-export --path src/ --path docs/ main > repo.stream |
| With prefix | git fast-export --prefix=services/A/ --all > repo.stream |
| Anonymized | git fast-export --anonymize --all > repo.stream |
| Show original IDs | git fast-export --show-original-ids --all > repo.stream |
| Incremental | git fast-export --export-marks=marks --import-marks=marks --all |
Import
| Task | Command |
|---|---|
| Into fresh repo | mkdir t && cd t && git init && git fast-import < stream && git reset --hard HEAD |
| Into existing | git fast-import < stream && git reset --hard HEAD |
| With marks tracking | git fast-import --export-marks=.git/marks --import-marks=.git/marks < stream |
| Over SSH | ssh host "cd /repo && git fast-import" < stream |
Stream format
blob
mark :1
data <bytes>
<content>
commit refs/heads/main
mark :2
author Name <e> <ts> +0000
committer Name <e> <ts> +0000
data <bytes>
<message>
from :1
M 100644 :1 README.md
tag refs/tags/v1.0
mark :3
tagger Name <e> <ts> +0000
data <bytes>
<tag message>
from :2
doneFile change commands inside commits
| Cmd | Mode | Action |
|---|---|---|
M 100644 :mark path | 644/755/120000/160000 | Add/modify file |
D path | — | Delete file |
C old new | — | Copy file |
R old new | — | Rename file |
deleteall | — | Clear entire tree |
DevOps one-liners
bash
# Consolidate repos under prefixes
for repo in A B C; do git -C $repo fast-export --prefix=$repo/ --all; done | git fast-import
# Split one directory into its own repo
git fast-export --path=services/A --all > split.stream
# Pipe across hosts (anonymized)
ssh src "cd /repo && git fast-export --all --anonymize" | cd /debug && git init && git fast-import
# Generate synthetic 10-commit repo
for i in $(seq 10); do echo "blob"; echo "mark :$((i*2-1))"; echo "data 3"; echo "v$i"; echo "commit refs/heads/main"; echo "mark :$((i*2))"; echo "author T <t@t> $(($(date +%s)+i*100)) +0000"; echo "committer T <t@t> $(($(date +%s)+i*100)) +0000"; echo "data 3"; echo "v$i"; [ $i -eq 1 ] && echo "feature date-format=raw" || echo "from :$((i*2-2))"; echo "M 100644 :$((i*2-1)) f-$i.txt"; echo ""; done; echo "done" | git fast-importMarks: incremental migration
# Phase 1
git -C src fast-export --export-marks=marks --all | git -C dst fast-import --export-marks=marks
# Phase 2 (days later)
git -C src fast-export --export-marks=marks-new --import-marks=marks --all | git -C dst fast-import --export-marks=marks --import-marks=marks-newSee also
docs/devops-workflows/git-fast-import-export.md— full guide with patternsscripts/fast-import-manage.sh— automation wrapper