MyGit is a lightweight, custom version control system built using Node.js. It tracks file changes using Merkle Trees, ensuring efficient comparison of file states across commits.
- Initialize a Repository: Create a
.mygit/
directory with necessary metadata. - Track File Changes: Add files to the index and detect modifications.
- Commit Changes: Store file states and maintain a version history.
- Efficient Change Detection: Uses Merkle Trees to compare commits quickly.
- Checkout Commits: Restore previous file versions.
- Compare Commits: Determine whether changes exist between commits.
- Show Status: List modified, new, and deleted files.
# Clone this repository
git clone https://github.com/yourusername/mygit.git
cd mygit
# Install dependencies
npm install
const git = new MyGit();
This creates the .mygit/
directory with necessary folders and files.
git.add("./sample/file1.txt");
This stores a hashed version of the file in .mygit/objects/
.
git.status();
Outputs:
🔍 Status:
🆕 New: ["file.txt"]
✅ No changes detected!
git.commit("Initial commit");
Outputs:
Committed as d1a2b3c4 (Merkle Root: a1b2c3d4e5)
git.compareCommits(<hash1>, <hash2>);```
Outputs:
Comparing d1a2b3c4 ↔ e5f6g7h8 ❌ Changes detected! (Merkle roots differ)
### 6️⃣ Checkout a Commit
```sh
git.checkout(<commit_hash>)
This restores files from a previous commit.
-
Adding Files:
- Hashes the file content and stores it in
.mygit/objects/
. - Updates the
.mygit/index
file to track the latest version.
- Hashes the file content and stores it in
-
Committing Changes:
- Builds a Merkle Tree using file hashes.
- Saves commit metadata in
.mygit/commits/
. - Updates
.mygit/branches/main.json
with the latest commit.
-
Comparing Commits:
- Retrieves Merkle roots of both commits.
- If the roots match, no changes are detected.
- If they differ, specific files are identified as changed.
-
Checking Out a Commit:
- Reads commit data and restores the files.
- Node.js - Core runtime
- File System (fs) - Handling file operations
- Crypto - Hashing file contents for integrity
- Merkle Trees - Efficient change tracking
- ✅ Implement branching
- ✅ Support remote repositories
- ✅ Improve CLI interface with better UX
This project is licensed under the MIT License.
👨💻 Developed by Your Name
📌 Version Control Simplified!