中文文档 | 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
Git
implementation 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
- Windows
- MacOS
- Linux (Unix-like...)
-
Supports input paths (pathspec): file paths, directory paths (absolute or relative, including
.
,./
,../
) -
Supports
mit init
,mit add
,mit rm
,mit commit
-
init
: Initialize (does nothing if the repository already exists) -idempotent
-
add
: 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
-
commit
-
status
: 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 restore
-
branch
-
switch
Unlikecheckout
,switch
requires specifying--detach
to 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
--source
is not specified and neither--staged
nor--worktree
is specified, restore to theHEAD
version, otherwise, restore from the staging area [index
] - If neither
--staged
nor--worktree
is 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)
--test-threads=1
when executing tests.
For example:cargo test -- --test-threads=1
This is because testing involves IO on the same folder.
- Staging area:
index
orstage
, stores file snapshots needed for the nextcommit
- Working directory:
worktree
, the folder directly manipulated by the user - Repository:
working directory
orrepository
, the root directory of the code repository, where.mit
is located HEAD
:Points to the currentcommit
- Tracked:
tracked
,files already in the staging area [index
](i.e., files that have beenadd
-ed)
【Mit】Rust implementation of Mini-Git - System Software Development Practice Final Report_Bilibili