Skip to content

Latest commit

 

History

History
43 lines (29 loc) · 1000 Bytes

git-objects.md

File metadata and controls

43 lines (29 loc) · 1000 Bytes

Git Objects

Step1: Git

Before we start writing Git, we should get acquainted with it:

  1. Learn some popular Git commands: add, commit, push, pull, fetch, reset
  2. Get some acquaintance with Git internals. This is a popular topic, so there are plenty of videos available, like this one for example. Additionally there's a respective chapter in Git Book.

Step2: Sha

You already have learned that any Git Object is represented by its hash based ID generated by SHA-1 algorithm. You task is to implement this:

class Sha {
    private final String hex;
    
    public Sha(String hex) {
        this.hex = hex;
    }
    
    public static Sha from(byte[] content) {
        ...
    }
    
    public String hex() {
        return hex;
    }
    
    public String toString() {
        return hex;
    }
}

Don't forget to write unit tests.

Blob

Tree

Commit