Clone — A Git Like Version Control System

Shehan Rathnayake
5 min readNov 11, 2023

--

Introduction

I hope most of you who read this story have used Git at least once. So, have you ever thought about how Git works? How does it track all the files and keep track of records? Well, Git saves a snapshot of the entire project at each commit of a specific moment. Mainly Git uses blob objects, tree objects, and hashing technologies for its entire operation. So, here I am not going to deeply explain how Git works, because, I want to discuss how I thought to develop a Git-like version control system using my knowledge for experiment purposes. I called it ‘Clone’.

Clone is a Git-like versioning control system that can be used to manage source codes and any other contents in an efficient way. This has been created basically using Java File I/O system and hashing technologies.

Clone application logo
Application logo

Access the GitHub repository from here 👈

Download the .deb file for Ubuntu users 👈

How The App Works

The app is based on the concept of clones. The word ‘clone’ is normed for commits in Git to represent a track record. Each track record is called a ‘clone’ and we can activate each ‘clone’ if we want to surf the history of track records.

Like in Git, Clone also has a hidden folder (.clone) created when the new repository is created which is normed ‘The Clone Factory’. All the track records and other essential data are stored here.

The clone factory folder
.clone folder- The Clone Factory

The app is working according to commands from the terminal. There are predefined commands I have created to work with this. They will be discussed one by one later in this story. The app is triggered to the particular commands and exits after the work is done just like Git.

So after every command, it is necessary to keep records of changes to use in the next steps. For that, I used to write and read the records in files using the Java SE File I/O system.

To keep the references of data like user contents and commit details, I had to use hashing algorithms which was very helpful. Not only keeping the references but also keeping them in a well-structured format is a must for the efficiency of the app. To make that real, I used Java ArrayList to store the reference data in the files.

Technologies Used

As I discussed in the previous section, the following technologies were mainly used to make this app real.

  • Java programming language
  • Java SE File I/O system
  • Java SE hashing algorithms

Java Se File I/O System

File Input/output streams, buffer input/output streams, and object input/output streams were mainly used to read the contents from the files and write the new data into the files.

    private static Object readFileContent(String filePath) throws IOException {
File dbFile = new File(filePath);
FileInputStream fis = new FileInputStream(dbFile);
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
Object cloneObject;
try {
cloneObject = ois.readObject();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} finally {
ois.close();
}
return cloneObject;
}

private static void writeFileContent(String filePath, Object content ) throws IOException {
File tempFile = new File(filePath);
FileOutputStream fos = new FileOutputStream(tempFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(bos);
try {
oos.writeObject(content);
} finally {
oos.close();
}
}

Hashing Algorithm

To compare the changes in the contents, to give a unique name to every clone, this hashing technology was really helpful. The method that returns the hashing string according to the given content is as below.

    static String calculateHashCode(byte[] byteArray) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashArray = digest.digest(byteArray);

StringBuilder hexStringCode = new StringBuilder();
for (byte b : hashArray) {
String hex = String.format("%02X", b);
hexStringCode.append(hex);
}
return hexStringCode.toString();
}

Installation Guide

For Ubuntu users, I have created a .deb file from the latest version. They can use the following command to install the .deb package into the computer.

sudo dpkg -i clone-0.8.0-ubuntu.deb

Access the GitHub repository from here 👈

Download the .deb file for Ubuntu users 👈

After the installation, you can check whether the app is installed into the computer successfully using commands clone or clone -v or clone –version

Introductory command
Introductory command

User Guide

The following commands can be used to work with the app.

clone - To check whether the app is installed properly into the computer

clone [-h | - help] - To see the command list

clone [-v | - version] - To see the version

clone show - To see the current status of files

clone start - To start the clone repository

clone make - Getting ready all the files for saving

clone save - Saving a snapshot of the current project

clone log - Displaying all the clones saved

clone activate <hashcode> - Traversing history through saved clones

Sample Demonstrations

version and help commands
Help and Version commands through the terminal
Commands from the terminal
Commands from the terminal
Checking the app is installed properly
Checking the app is installed properly
Starting a clone factory inside the folder
Starting a clone factory inside the folder
Saving a clone
Saving a clone
Checking the content status
Checking the content status
Checking the clone logs
Checking the clone logs
Surfing history through activating clones
Surfing history through activating clones

Conclusion

In conclusion, the development of Clone, a Git-like version control system, provides an insightful exploration into the inner workings of versioning systems. The inspiration drawn from Git’s principles led to the creation of a Java-based application that leverages File I/O systems and hashing technologies to efficiently manage source codes and track records.

Overall, the development and functionality of Clone demonstrate a thoughtful approach to version control, providing users with a tool that echoes Git’s principles while introducing its own unique features. The article serves as a comprehensive guide for understanding Clone’s architecture, installation process, and practical usage, inviting readers to explore and experiment with this Git-inspired version control system.

In addition, I hope to continuously develop this amazing product introducing new features like branches, cloud repositories, etc. in the future.

Access the GitHub repository from here 👈

Download the .deb file for Ubuntu users 👈

--

--

Shehan Rathnayake

Software Engineer | Fueled by curiosity and dedication | Coding my way to excellence 🔥 | Exploring the World of Information Technology 🚀