txtar is a command-line tool for creating, inspecting, extracting, and comparing txtar archives.
- Pack a directory into a
txtararchive - Pack files from a Git repository snapshot or changed files
- Unpack archives to the filesystem with overwrite safeguards
- List archive contents
- Diff two archives, or diff a directory against an archive
Install with Go:
go install github.com/phlv/txtar@latestOr build from source:
git clone https://github.com/phlv/txtar.git
cd txtar
make buildThe binary will be written to build/txtar.
txtar [--config FILE] <command> [flags]Global flag:
--config: use a specific config file instead of the default search path
Config lookup:
$HOME/.config/txtar/config.yaml./config.yaml
Create a txtar archive from a directory or a Git-backed file set.
txtar pack [DIR] [flags]If DIR is omitted, the current directory is used.
Flags:
-o, --output: output file path,-means stdout. Default:--i, --include: include glob pattern, repeatable-e, --exclude: exclude glob pattern, repeatable--git: enable Git-aware packing--diff: pack files from the current Git diff, including staged, unstaged, and untracked files; requires--git--commit: pack a specific commit snapshot, requires--git--since: pack files changed across the lastNcommits, requires--git--staged: pack staged files from the working tree, requires--git--worktree: pack modified worktree files, requires--git--strip-prefix: remove a path prefix from archived file names--dry-run: print the files that would be packed instead of writing an archive--ignore-binary: skip files detected as binary--txtarignore: ignore file name to load fromDIR. Default:.txtarignore
Behavior notes:
- Without
--git,packwalks the filesystem underDIR. - With
--gitand no extra Git selector flags,packarchives the currentHEADcommit snapshot. --diff,--commit,--since,--staged, and--worktreeare mutually exclusive Git selection modes.--git --diffpacks the current working tree diff: staged files, unstaged files, and untracked files..gitignoreis only loaded in--gitmode..txtarignoreis loaded fromDIRwhen present.- In
--dry-runmode, the file list is printed to stdout. - Deleted files may appear in Git status but are skipped because there is no file content to archive.
Examples:
txtar pack . -o archive.txtar
txtar pack . -e '*.log' -e 'node_modules/**' -o archive.txtar
txtar pack . -i 'cmd/**' -i 'internal/**' -o src.txtar
txtar pack . --git --commit HEAD~1 -o head-minus-1.txtar
txtar pack . --git --since 3 -o recent-changes.txtar
txtar pack . --git --diff -o working-tree.txtar
txtar pack . --git --staged -o staged.txtar
txtar pack . --git --worktree --ignore-binary --dry-run
txtar pack . --strip-prefix internal/ -o internal.txtarExtract a txtar archive to a directory.
txtar unpack [ARCHIVE] [flags]If ARCHIVE is omitted or set to -, data is read from stdin.
Flags:
-C, --dir: output directory. Default:.--backup: rename an existing file to*.bakbefore overwriting--dry-run: print planned writes without creating files--no-overwrite: fail if a target file already exists
Behavior notes:
--backupand--no-overwriteare mutually exclusive.- Archive entries using absolute paths or
..path traversal are rejected. - When
--backupis enabled andfile.bakalready exists, a timestamped backup name is used.
Examples:
txtar unpack archive.txtar
txtar unpack archive.txtar -C out
txtar unpack archive.txtar --backup -C out
txtar unpack archive.txtar --no-overwrite -C out
cat archive.txtar | txtar unpack - -C out
txtar unpack archive.txtar --dry-run -C outPrint the file paths stored in an archive.
txtar list [ARCHIVE]If ARCHIVE is omitted or set to -, data is read from stdin.
Examples:
txtar list archive.txtar
cat archive.txtar | txtar listCompare two archives, or compare a directory to an archive.
txtar diff [LEFT] [RIGHT] [flags]Flags:
--dir: treatLEFTas a directory instead of an archive-c, --content: show content differences for modified files
Output markers:
+: file exists only inRIGHT-: file exists only inLEFTM: file exists in both sides but contents differ
Examples:
txtar diff left.txtar right.txtar
txtar diff left.txtar right.txtar --content
txtar diff --dir ./workspace archive.txtar
txtar diff --dir ./workspace archive.txtar --contentOptional config file: ~/.config/txtar/config.yaml
Supported keys:
pack:
output: "-"
default_exclude:
- "*.log"
- "node_modules/**"
ignore_binary: true
unpack:
backup: false
dir: "./out"Notes:
pack.default_excludeis prepended to CLI--excludevalues.pack.ignore_binaryis used only when--ignore-binaryis not set explicitly.unpack.backupandunpack.dirare used only when the matching CLI flags are not set explicitly.
Available make targets:
make buildmake testmake fmtmake vetmake lintmake install
MIT