Creating a Git Commit: The Hard Way

184 pointsposted 5 days ago
by avestura

19 Comments

jeroen

an hour ago

> Files in Git can be in one of these three states: Modified, Staged, Committed

> Staged: The current version of the modified file is staged to be included in the next commit.

A bit of a nitpick, but if I change a file, "git add" it, and then change it again, both of these statements are false.

jjmarr

31 minutes ago

I use git add -p somewhat frequently to do partial staging of a file to split up my changes into multiple commits.

archmaster

15 hours ago

This is pretty cool. Worth noting that Git does not actually only store full copies of files every time you make a change, this article I found does a really good job at explaining Git's packing: https://gist.github.com/matthewmccullough/2695758

glandium

8 hours ago

It actually does. Until you run git gc or it runs automatically, and your blobs are packed.

masklinn

7 hours ago

“Objects” rather than “blobs”, in git “blobs” means specifically file contents (/ unstructured as technically you can use blobs for arbitrary storage) but all objects can be delta’d during packing.

chrisweekly

15 hours ago

Nice writeup. Reminds me of a Julia Evans post (which is the highest praise I could give it).

AndreasHae

an hour ago

Fantastic article! It seems to me that the flexibility of low-level git objects would lend itself to be embedded in other software systems for version control purposes (e.g. tracking changes in a CMS)

larusso

7 hours ago

Nice article. What is interesting to me is the reactions to articles like this. Not the fact that the git internals are not widely known, I mean that is true for nearly any more complicated topic. In this case I mean the fact that this is actually well documented.

Don’t get me wrong. I think articles like these help a lot to demystify git and I believe it makes the tool easier to use and reason with when one knows what it does. But why is nobody finding or reading the later chapters in the docs?

https://git-scm.com/book/en/v2/Git-Internals-Git-Objects

avestura

7 hours ago

Creating a Git commit using low-level commands was always something I wanted to do, but I never found the time to really deepen my knowledge of Git. I have actually googled if I could find a blog post or something in this topic, but I've failed to find one. Finally, I got the chance, and for the past couple of weekends, I’ve been reading the Pro Git book (which it seems it's the same content as git-scm.com/book). I believe it’s a good practice to write a blog post about a topic after finishing a book (teaching is a good way of submitting knowledge in memory). To my surprise, creating a Git commit using plumbing commands was already covered in the final chapters of the book. I thought it would be a good idea to simplify that process and write a blog post which can be read under 10 minutes, allowing those who haven’t read the book yet (like myself in the past) to get a basic understanding of what Git is doing under the hood.

> But why is nobody finding or reading the later chapters in the docs?

I think to read the latest chapter of a book, one usually needs to read the earlier ones too. I personally don't jump directly to the internals when I want to read about something, because I'd then assume I am missing a lot of context and background.

ErikBjare

31 minutes ago

I haven't read a "book" like this chapter-by-chapter since I first learned Python by reading the docs.

forgotpwd16

5 hours ago

Up to commit-tree, a nice programming challenge is implementing those commands from scratch.

faangguyindia

10 hours ago

I used to struggle with formatting my Git commit messages and often forgot the necessary Git commands.

Now, I've found a utility (made by my brother who shared it with me a few days ago and I told him to opensource it since I liked it soo much) that handles all the formatting and rewriting for me. I just write my commits, and it takes care of the rest.

Here's a video demonstrating this magic (though it's for rsync): [asciinema.org/a/mktcuXSPDTr2Mp1XVbo5tqhK1](https://asciinema.org/a/mktcuXSPDTr2Mp1XVbo5tqhK1).

Check out the utility here: [github.com/zerocorebeta/Option-K](https://github.com/zerocorebeta/Option-K).

Vampiero

7 minutes ago

The last thing I want is for some LLM to tell me to rm -rf /. Neat POC but the tech just isn't there yet and I hope that everyone on HN who isn't shilling an AI product knows that.

nneonneo

10 hours ago

That repo is only nine hours old, so I’m assuming you wrote this tool yourself. If so, I think the lack of a disclaimer (that you’re promoting your own tool) is somewhat dishonest.

faangguyindia

9 hours ago

You are partially correct, but I am not the owner of this project.

I edited my original post to reflect this