A lightweight, Git-inspired version control system written in Java. Snapshot lets you track changes to text files, stage them, commit snapshots, and review history — all from the command line.
init— initialize a repository in the current directoryadd— stage individual files, multiple files, or entire directory treesrm— unstage a file without deleting itcommit— save a snapshot of all staged filesstatus— show staged changes, unstaged modifications, deletions, and untracked fileslog— display commit history (newest first) with timestamps in local time- Binary files are automatically detected and skipped
snapshot/
├── build.sh Build script (compiles + packages as snapshot.jar)
├── addToPath.sh Helper to install the 'snapshot' command system-wide
├── manifest.txt JAR manifest
├── src/
│ └── snapshot/
│ ├── Main.java CLI entry point and command dispatcher
│ ├── Utils.java Shared path constants, SHA-1 hashing, file I/O
│ ├── Repository.java init and status commands
│ ├── Index.java Staging area management (add / rm)
│ ├── Commit.java Commit creation and commit-data reading
│ └── Log.java Commit history display
└── .snapshot/ (created by 'snapshot init')
├── HEAD Hash of the latest commit
├── index Staging index (hash filepath per line)
└── objects/
├── staging/ Staged file content, keyed by SHA-1 hash
├── commits/ Per-commit object directories
└── refs/ Commit metadata files
- Java 17 or later
chmod +x build.sh
./build.shThis compiles the source and produces snapshot.jar.
chmod +x addToPath.sh
./addToPath.shThis creates an executable wrapper and copies it to /usr/local/bin/snapshot.
java -jar /path/to/snapshot.jar <command>Usage: snapshot <command> [args]
Commands:
init Initialize a new repository
add <file> [...] Stage files for commit (use '.' for all)
rm <file> Remove a file from the staging area
commit <message> Commit staged changes
status Show working directory and staging status
log Show commit history
# 1. Set up a repository
cd my-project
snapshot init
# 2. Stage files
snapshot add . # stage everything
snapshot add src/Main.java # or stage a single file
snapshot add a.txt b.txt c.txt # or multiple files
# 3. Review what will be committed
snapshot status
# 4. Commit
snapshot commit "Initial commit"
# 5. Make changes, then check what changed
snapshot status
# 6. Stage and commit the changes
snapshot add .
snapshot commit "Fix bug in parser"
# 7. View history
snapshot logChanges to be committed:
new file: src/Main.java
modified: README.md
Changes not staged for commit:
modified: config.json
deleted: old-file.txt
Untracked files:
notes.md
One entry per staged file:
<sha1-hash> <absolute-filepath>
time=<epoch-millis>
message=<commit message>
<sha1-hash> <absolute-filepath>
...
See CONTRIBUTING.md.
See CODE_OF_CONDUCT.md.
MIT — see LICENSE.
- build.sh: Script to build the project.
- data.txt: Data file used by the project.
- manifest.txt: Contains metadata for the project.
- object.txt: Stores object-related information.
- build/: Directory for compiled files.
- src/: Contains the source code for the project.
- Commit.java: Handles commit-related operations.
- HashObject.java: Manages hash object creation and retrieval.
- Index.java: Manages the index for tracking changes.
- Log.java: Handles logging of commit history.
- Main.java: Entry point for the application.
- Repository.java: Manages repository operations.
- Utils.java: Utility functions used across the project.
- Ensure you have Java installed on your system.
- Run the
build.shscript to compile the project:./build.sh
- Navigate to the
build/snapshotdirectory. - Run the
Mainclass using the Java command:java snapshot.Main
Before using this project, ensure the following:
- Java Development Kit (JDK) is installed on your system.
- The
JAVA_HOMEenvironment variable is set correctly. - You have a terminal or command prompt to execute commands.
- Clone or download the project to your local machine.
- Navigate to the project directory:
cd /path/to/snapshot
- Make the
build.shscript executable (if not already):chmod +x build.sh
- Run the build script to compile the project:
This will compile the Java source files and place the compiled classes in the
./build.sh
build/snapshotdirectory.
- After building the project, navigate to the
build/snapshotdirectory:cd build/snapshot - Run the
Mainclass to start the application:java snapshot.Main
The Snapshot application provides several commands to manage and track changes in your project. Below are the detailed steps for using the application:
To start using Snapshot, initialize a repository:
snapshot initThis command sets up the necessary files and directories for version control.
To track specific files, add them to the index:
snapshot add <file1> <file2>Replace <file1> and <file2> with the names of the files you want to track.
To save the current state of tracked files, create a commit:
snapshot commit "Commit message"Replace "Commit message" with a descriptive message about the changes.
To see the history of commits, use the log command:
snapshot logThis will display a list of all commits, including their hash, author, date, and message.
To view the current status of the repository, including staged and unstaged changes, run:
snapshot statusTo restore a file to a previous state, use the checkout command:
snapshot checkout <commit-hash> <file>Replace <commit-hash> with the hash of the commit you want to restore from, and <file> with the name of the file.
To stop tracking a file, remove it from the index:
snapshot rm <file>Replace <file> with the name of the file to untrack.
Here is an example workflow to demonstrate how to use Snapshot:
- Initialize a repository:
snapshot init
- Add files to the index:
snapshot add file1.txt file2.txt
- Commit the changes:
snapshot commit -m "Initial commit" - Make changes to
file1.txtand check the status:snapshot status
- Commit the changes:
snapshot commit -m "Updated file1.txt" - View the commit log:
snapshot log
- Build Errors: Ensure that the
build.shscript is executable and that you have the correct version of Java installed. - Command Not Found: Ensure the
snapshotcommand is in your system's PATH. You can add it by creating an alias or adding the project directory to your PATH. - Permission Denied: Use
chmod +xto make scripts executable.
- The
data.txt,manifest.txt, andobject.txtfiles are used internally by the application to store metadata and object information. Do not modify these files manually. - Always provide meaningful commit messages to make it easier to track changes.
For further assistance, refer to the source code in the src/snapshot directory or contact the project maintainers.
- Commit tracking
- File indexing
- Repository management
- Logging of changes
Contributions are welcome! Feel free to fork the repository and submit pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.