A very personal Git implementation

Probhakar
3 min readSep 1, 2022

--

Trying to code git internals while on a holiday

I have discussed the git internal, like how it works and it's core components (blob, tree & commit) in my previous article.

Shit is a very fragrant version of git written in python. As of now, it has basic core functionality. Check the source code here.

Usage

download the source code from the git repository on your local machine. It uses python3 so make sure you have python installed and working. It will look like this —

Open a command prompt and create an alias for the executable —

windows

doskey shit=<absolute-path-till>shit.py $*

It is not necessary, you can initiate the command using the full path command like C:\users\project\python3\shit\shit.py <command> but creating an alias makes our life easier.

Create a folder and create some files. Not go to that directory and put

shit

You will see this cool ASCII art 😊

     _     _ _
| | (_) |
___| |__ _| |_
/ __| '_ \| | __|
\__ \ | | | | |_
|___/_| |_|_|\__| version: 1.0.0

Go on initialize an empty repository —

shit init

You will see a new folder .shit where the necessary files & folder structure is kept.

shit status

status will show you the difference between the current working tree and the staging tree.

You can add a single file or all the files using wildcard .

shit add ./some_file.txtshit add .

If you edit or modify files, it will show the difference. Let me modify the content of ./some_file.txt

It shows the affected files. Internally shit uses SHA256 hashing to compute the difference.

We can commit

shit commit "first commit"

Go, on edit → stage → commit multiple. Use the

shit log

to view the commit log

The last functionality that shit provides is to reset the current working tree to some commits.

shit reset <last 4 or so digists of commit hash>shit reset aa0f

will reset the current working tree to the snapshot of the aa0f commit.

--

--