Minimal Git-like implementation in Swift. It supports repo initialization, staging, committing, status, and log, with Git-style object storage and optional compression. Built as a SwiftPM executable for macOS 10.15+.
mygit initsets up.mygit/,objects/,refs/,HEAD, and an empty index.mygit add <file>hashes content (SHA-1), stores blobs, and updates the staging index.mygit commit -m "msg"builds trees from the index, links parent commits, records author/committer/timestamps, writes commit objects, and updates refs/HEAD.mygit statusshows modified/deleted/untracked files relative to the index.mygit logwalks commit history from HEAD and prints commits.- Global flags:
--verbosefor tracing actions,--compressto zlib-compress stored objects.
- macOS 10.15+
- Swift toolchain with CryptoKit available (Command Line Tools or Xcode)
swift buildFrom the package root:
# Initialize a repository
.build/debug/MyGit init
# Stage a file
.build/debug/MyGit add path/to/file.txt
# Commit staged changes
.build/debug/MyGit commit -m "Initial commit"
# Inspect status
.build/debug/MyGit status
# View history
.build/debug/MyGit logGlobal flags can precede the command:
.build/debug/MyGit --verbose --compress add file.txtUses environment variables if set:
MYGIT_AUTHOR_NAME,MYGIT_AUTHOR_EMAILMYGIT_COMMITTER_NAME,MYGIT_COMMITTER_EMAILFalls back to system user info when unset.
- Objects are stored Git-style under
.mygit/objects/aa/bb.... Compression is optional. - The index is a simple JSON mapping of path → blob hash (staged snapshot).
- HEAD defaults to
refs/heads/main; commits update the branch ref or write directly to HEAD when detached.