Commitra is a lightweight, Git-inspired version-control system written in Java. It mimics the core functionality of Git, allowing users to initialize a repository, save snapshots of their files (commits), manage different development lines (branches), and merge histories.
All repository data is stored in a .commitra directory at the root of the project.
This project uses a Makefile for easy compilation.
-
To compile all source code:
make
(or
gmake) -
To clean up compiled
.classfiles:make clean
All commands are run from the command line through the Main class:
java commitra.Main [command] [args...]-
initInitializes a new, empty Commitra repository in the current directory. This creates the.commitrafolder and a "master" branch with an initial commit. -
statusDisplays the current state of the repository, including branches, staged files, files staged for removal, modifications not staged, and untracked files.
-
add [file-name]Adds the current version of a file to the staging area, preparing it to be included in the next commit. If the file is identical to the version in the current commit, it is not staged. -
rm [file-name]Stages a file for removal. The file will be removed from the working directory and will no longer be tracked in the next commit. -
commit [message]Saves a snapshot of the current staging area as a new commit. The commit will include the provided message, a timestamp, and a reference to its parent commit(s).
-
logDisplays the commit history for the current branch, starting from the head commit and following its parentage. -
global-logDisplays the history of all commits ever made in the repository, regardless of branch. -
find [commit-message]Searches for and prints the SHA-1 IDs of all commits that have the exact commit message provided.
-
branch [branch-name]Creates a new branch that points to the current head commit. -
switch [branch-name]Switches the current active branch (HEAD) to the specified branch and updates the working directory to match that branch's last commit. -
rm-branch [branch-name]Deletes the branch with the given name. You cannot delete the branch you are currently on. -
merge [branch-name]Merges the specified branch into the current branch. This may result in a new "merge commit". If conflicts are found, the user will be notified.
-
checkout -- [file-name]Restores the specified file in the working directory to its version from the current head commit. -
checkout [commit-id] -- [file-name]Restores the specified file in the working directory to its version from the specified commit. -
reset [commit-id]Resets the current branch's head to the specified commit. It also updates the working directory to match the files in that commit.
All data is persisted through Java's serialization mechanism. The .commitra directory holds the following:
/objects/: Stores all file contents ("blobs") as serialized byte arrays, named by their SHA-1 hash./commits/: Stores allCommitobjects as serialized files, named by their SHA-1 hash./branches/: Contains serializedBranchobjects, one file for each branch, pointing to its respective head commit./branches/head.txt: A special file that stores the currently active serializedBranchobject.staging.txt: Stores the serializedStagingAreaobject, which tracks files to be added or removed.global.txt: A plain text file that keeps a log of all commit messages for theglobal-logcommand.