File handling

Hihi, I have some questions here and I hope that you all can help me out with them. So I was trying to create a Java program that mimics some of the functions that git has. But I need some guidance on the suitable ways to do it. Let’s call the program not-git. It has the similar basic functions that git has, including the 1. status command showing the status of files in the respective folder (tracked/not tracked), 2. add command adding a file to the repository while tracking it (e.g. add “file.txt”), 3. commit command to commit the files being tracked with an increasing counter (commit id). 4. revert command to reverse the version of current file into the previous version with a new commit ID (e.g. revert 1 will revert current version into version of commitID 1 but now the new version will have a new commitID, if before reverting the commitID is 2 now the commitID will be 3 for this version). I have attached some images below (I tried uploading ppt, docs and pdf but none of them works) if the explanation above isn’t clear enough. I have some ideas in mind but not sure whether it is feasible, so I will create a LinkedList that accepts file as its parameter and store it in a node when an add command is issued, and there will be a counter with a default value of 1 that increases per commit. Whenever a revert command is issued, the list will be used to lookup the content of the node index. The functions mentioned above were just the basic requirements to achieve the passing marks, to achieve better grades we were suggested to add extra features like modifying the status command into showing not only the tracked files but also the new files, untracked files, and the modified files. The other extra features to improve the program are also included in the file uploaded. Thank you for taking your time reading this and I appreciate any help provided!


The main concern here is how do I collect a pile of files and store them into one node of LinkedList. And also when I revert how do obtain the files from the prev commit and replace the current ones. Thank you in advance for any help incoming!
And also how to know when the content of the file is altered (modified)? Since the assignment requires to display the status of files not only tracked/untracked but also modified/new.

My codes:

import java.util.*;

public class notGit {

LinkedList list; //stores file history
LinkedList list1; //stores list for each commit
int commitID; //increases per commit

public notGit() { //initialization
    this.list = new LinkedList();
    this.list1 = new LinkedList();
    this.commitID = 1;

void add(File file) {
    System.out.printf("\"%s\" is now being tracked\n", file.getName());

void commit() {
    System.out.printf("files committed with commit id \"%d\"\n", commitID++);

void revert(int i) {
    list = (LinkedList) list1.get(i - 1);
    System.out.printf("revert to commit-id \"%d\" and committed with commit-id \"%d\"", --commitID, commitID += 2);

void status() {
    if (list.isEmpty()) {
        System.out.println("No file is being tracked.");
    } else {
        System.out.println("tracked files:");
        for (int i = 0; i < list.size(); i++) {
            File n = (File) list.get(i);

void check(String s) throws IOException {
    if ("not-git".equals(s)) {
        System.out.println("Welcome to not-git!");
    } else if ("status".equals(s)) {
    } else if (s.startsWith("add")) {
        String[] arr = s.split("\"");
        File newF = new File(arr[1]);
    } else if ("commit".equals(s)) {
    } else if (s.startsWith("revert")) {
        String[] arr = s.split(" ");
    } else {
        System.out.println("Please enter the correct command: ");



public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        notGit newGit = new notGit();
        String s;
        System.out.println("Enter \"not-git\" to initialise the program:");
        do {
            s = br.readLine();
            if (!"not-git".equals(s)) {
                System.out.println("Please enter the instructed command:");
        } while (!"not-git".equals(s));
        while ((s = br.readLine()) != null) {
            if ("not-git".equals(s)) {
                newGit = new notGit();