4.0 KiB
MIT: Mini-Git implementation in Rust
中文文档 | English
Git in Rust. A mini Git implementation calledmit, implemented in Rust.
Designed to be concise, readable, efficient, and secure.
The best way to learn Git is to implement Git.
This project aims to provide a
Gitimplementation that even a second-grader can understand.
// rm -rf rigid design patterns & complex repository architecture
NOTE: For a more comprehensive implementation of Git, please refer to another project of ours:
Mega-Libra
Cross-Platform Support
- Windows
- MacOS
- Linux (Unix-like...)
Key Features
-
Supports input paths (pathspec): file paths, directory paths (absolute or relative, including
.,./,../) -
Supports
mit init,mit add,mit rm,mit commitinit: Initialize (does nothing if the repository already exists) -idempotentadd: Add changes to the staging area (including new, modified, deleted), can specify files or directories-A(all): Stage all changes in the working directory (from the root) (new✅ modified✅ deleted✅)-u(update): Operate only on tracked files in the staging area [index] (new❌ modified✅ deleted✅)
rm: Remove files from the staging area & working directory--cached: Remove only from the staging area, untrack-r(recursive): Recursively delete directories, must specify this parameter when deleting directories
commitstatus: Display the status of the working directory, staging area, andHEAD(only for the current directory); divided into three parts:- Staged to be committed: Changes staged in the staging area compared to
HEAD(lastCommit::Tree), i.e., the last staging area - Unstaged: Changes in the working directory not staged in the staging area
- Untracked: Files in the working directory not staged or tracked before
- Staged to be committed: Changes staged in the staging area compared to
log
-
Supports branches
mit branch,mit switch,mit restorebranchswitchUnlikecheckout,switchrequires specifying--detachto switch to acommit, otherwise, it can only switch branches.restore: Rollback files- Restore files at the specified path (including directories) to the version specified by
--source, can specify staging area & working directory--source: Can specifyCommit Hash,HEAD, orBranch Name
- If
--sourceis not specified and neither--stagednor--worktreeis specified, restore to theHEADversion, otherwise, restore from the staging area [index] - If neither
--stagednor--worktreeis specified, default to restore to--worktree - For files not present in
--source, if tracked, delete; otherwise, ignore
- Restore files at the specified path (including directories) to the version specified by
-
Supports simple merging
mit merge(fast-forward)- Merge(FF)
Notes
⚠️Testing requires single-threading
⚠️ Note: To avoid conflicts, please use --test-threads=1 when executing tests.
For example:cargo test -- --test-threads=1
This is because testing involves IO on the same folder.
Term Definitions
- Staging area:
indexorstage, stores file snapshots needed for the nextcommit - Working directory:
worktree, the folder directly manipulated by the user - Repository:
working directoryorrepository, the root directory of the code repository, where.mitis located HEAD:Points to the currentcommit- Tracked:
tracked,files already in the staging area [index](i.e., files that have beenadd-ed)
Introductory Video
【Mit】Rust implementation of Mini-Git - System Software Development Practice Final Report_Bilibili