Skip to content

mohamedhesham124/Commitra

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 

Repository files navigation

Commitra

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.

Compilation

This project uses a Makefile for easy compilation.

  • To compile all source code:

    make

    (or gmake)

  • To clean up compiled .class files:

    make clean

How to Use

All commands are run from the command line through the Main class:

java commitra.Main [command] [args...]

Repository Commands

  • init Initializes a new, empty Commitra repository in the current directory. This creates the .commitra folder and a "master" branch with an initial commit.

  • status Displays the current state of the repository, including branches, staged files, files staged for removal, modifications not staged, and untracked files.


Staging and Committing

  • 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).


History and Inspection

  • log Displays the commit history for the current branch, starting from the head commit and following its parentage.

  • global-log Displays 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.


Branching and Merging

  • 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.


File Restoration

  • 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.

Project Structure

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 all Commit objects as serialized files, named by their SHA-1 hash.
  • /branches/: Contains serialized Branch objects, one file for each branch, pointing to its respective head commit.
  • /branches/head.txt: A special file that stores the currently active serialized Branch object.
  • staging.txt: Stores the serialized StagingArea object, which tracks files to be added or removed.
  • global.txt: A plain text file that keeps a log of all commit messages for the global-log command.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 95.5%
  • Makefile 4.5%