Lit is a simple, Git-inspired version control system built in JavaScript. It provides basic version control functionality through a command-line interface, implementing core Git concepts like staging, committing, and viewing history.
- Repository Management: Initialize new repositories with
lit init
- Staging Area: Add files to staging with
lit add <file>
- Commits: Create commits with descriptive messages
- History: View commit history and changes with
lit log
- Diff Viewing: See changes between commits with
lit show <commit-hash>
- Content Addressing: Files and commits are stored using SHA-1 hashes
- Node.js (version 14 or higher)
- npm (comes with Node.js)
- Clone the repository:
git clone <repository-url>
cd lit-vcs
- Install dependencies:
npm install
- Install the
lit
command globally:
npm install -g .
Now you can use lit
from anywhere in your system!
- Clone and install dependencies:
git clone <repository-url>
cd lit-vcs
npm install
- Create a symlink for development:
npm link
- Make the script executable:
chmod +x main.mjs
lit init
Creates a new .lit
repository in the current directory. This sets up the internal structure needed for version control.
lit add <filename>
Adds the specified file to the staging area. The file content is hashed and stored in the objects directory.
Example:
lit add main.js
lit add README.md
lit commit "Your commit message here"
Creates a commit with all files currently in the staging area. The staging area is cleared after a successful commit.
Example:
lit commit "Add initial project setup"
lit commit "Fix bug in file handling"
lit log
Displays a chronological history of all commits, showing commit hashes, timestamps, and messages.
lit show <commit-hash>
Shows the differences introduced in the specified commit, displaying added lines in green and removed lines in red.
Example:
lit show abc123def456
When you initialize a repository, Lit creates the following structure:
.lit/
├── objects/ # Stores file content and commit objects (SHA-1 hashed)
├── HEAD # Points to the current commit hash
└── index # Tracks staged files (JSON format)
Lit implements a simplified version of Git's internal model:
- Content Addressing: All file content is hashed using SHA-1 and stored in the
objects/
directory - Staging Area: The
index
file tracks which files are staged for the next commit - Commits: Each commit contains metadata (timestamp, message, parent) and references to file hashes
- History: Commits form a linked list, with each commit pointing to its parent
- HEAD: The
HEAD
file always points to the latest commit
# Initialize a new repository
lit init
# Add some files
lit add main.js
lit add package.json
# Make your first commit
lit commit "Initial project setup"
# Make some changes to files, then add and commit again
lit add main.js
lit commit "Add new feature"
# View your commit history
lit log
# See what changed in the last commit
lit show <latest-commit-hash>
lit-vcs/
├── main.mjs # Main CLI application
├── package.json # Project configuration and dependencies
└── README.md # This file
- commander: Command-line interface framework
- chalk: Terminal color formatting
- diff: Text diffing functionality
Currently, the project doesn't have automated tests, but you can test functionality manually using the commands above.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the ISC License.
This project is inspired by Git and serves as a learning tool to understand version control system internals.