9 ms·
Gitlet.js – Git implemented in 1k lines of JavaScript (2015)
- dcwca 6y agoThis is such great work.
- billconan 6y agothis is cool! but I'm curious to see a git blame implementation.
- phist_mcgee 6y agoYou mean the most conflict driven and passive aggressive feature in any programming tooling?
- asxd 6y agoI mean, it just tells you the commit that last changed a line...
- billconan 6y agoit's not that simple. git is a snapshot, i.e. it saves an entire file. How to recover changed lines from it efficiently? And How to do it for the entire history? Basically, I want to understand this code https://github.com/git/git/blob/master/blame.c https://github.com/git/git/blob/master/blame.c
- adkadskhj 6y agoI'm so confused on what you're saying. Are you saying it _isn't_ what commit last occurred on the given line? How would you explain this UI? https://github.com/git/git/blame/master/blame.c https://github.com/git/git/blame/master/blame.c Ie, what does blame mean to you?
- asxd 6y agoI was replying to another comment that has since been deleted. It said something roughly along the lines of git blame being a contentious and passive aggressive command. I totally agree the technical implementation would be cool to study :)
- Stratoscope 6y agoIf you ever want to see "deleted" (flagged/dead) comments like that one, turn on "showdead" in your profile.
- asxd 6y agoAh I see it now, thanks for the heads up!
- SamBam 6y agoSomething tells me I wouldn't want to work in whatever team you work with. git blame is extremely useful for knowing when something was added, and what the context was. It is not about "blaming" people for mistakes.
- adkadskhj 6y agoYea, it strikes me as a poor name. Cheeky perhaps. I once had someone take me aside and ask me if it was rude to use "blame" in github to figure out who touched a specific line. They thought the name implied some sort of finger pointing and fault.
- masklinn 6y ago> Yea, it strikes me as a poor name. Other VCS have aliases like « annotate » for the operation.
- NobodyNada 6y ago`blame` is one of Git’s most useful features for me, because if I’m confused about a piece of code I can instantly check to see when that code was added and why. Does it fix a bug; if so what’s the bug tracker ID and how was it resolved? Why did the programmer chose to do things this way instead of some other way that seems more obvious? How did this change fit into the rest of the codebase, and were any other files or functions changed to match? (Of course, the utility of this depends on how well people write commit messages. There’s nothing more annoying than looking at a blame and seeing “update somefile.java.”) If your organization is using blame to stir up conflict and point fingers, that sounds like a human problem rather than a technical problem, and a problem that you would still have even if `git blame` never existed.
- sdesol 6y agoMy tool is designed to obtain insights from Git history and I've never understood how people can take such offense to git blame. I do agree calling it "blame" was probably not the best thing to do, but the fact is, it serves a purpose, which is, it's designed to help you understand how a piece of code came about. For you to call this feature "passive aggressive" must have been borne out of some traumatizing experience and for that, you have my sympathy.
- sodapopcan 6y agoThat's Linus for you, I guess? I dunno, I always found `git blame` really funny yet at the same time, I empathize with those who are a little taken aback by it (including... what's the company's name who makes IDEs who calls it "annotate"... ?). I largely love it because most of the time when I `blame`, that's exactly what I want to do. I don't need software to give me a nicer verb so I can pretend that's not what I'm actually doing. And most of the time, the author is exactly who I thought it was going to be (which can result in jovial convos) or, more commonly, ITS ME! Oh, the humility. I guess I can see it being a problem if you work on a toxic team (shit, sorry) and yes, I do understand desire for a sheen of positivity in the language of the software we use, but pretty much every of the time I go to call `git blame`, I mean `git BLAME`. While it certainly does happen, I rarely find myself thinking, "Who wrote this amazing code!?? I MUST KNOW!!!" and in those circumstances, it actually soothes my ego to "blame" them for it :D edited for grammar/spelling
- cjohansson 6y agoGit can also be an offensive word just like blame. It just depends on what attitude people have towards the context. I am not offended by git, blame, master and slave and I think it would be best if people who are offended just change their attitude towards the context
- 29athrowaway 6y agogit blame is mostly used to answer the question "when did this change and how?" Being able to answer that question is key for maintainers.
- quickthrower2 6y agoNah, that award is for team time logging tools. Blame is normally used as a "who to ask" tool. Often the answer it gives you is "who last refactored this file" or "who originally moved this file from another location and lost the link to the prehistoric era when the interesting stuff happened"
- lostcolony 6y agoAnother word for blame is 'responsibility'. In a political organization, it's good to take responsibility for something, but bad to blame. A generous interpretation of that is that the person/group who made the decision should raise their own hand, and that it's a faux pas for others to point them out. In a healthy one, you can recognize it's the same thing, and the important thing is how you respond to it (i.e., it's important to understand the responsible party so you can understand the reasons/motivations for the action, and accept them or address them).
- hu3 6y agoI'm sorry if you had bad experiences with git blame usage. People can be assholes sometimes. It's not meant to be a finger pointing tool but can be used for that.
- dang 6y agoPlease don't take HN threads on flamewar tangents. That's what we're trying to avoid here. https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- primitivesuave 6y agoThis is so cool, and also my first time seeing this brilliant format for long-form explanations of code. Is this a thing out there, and does anyone have any pointers on libraries that do this?
- fs_tab 6y agoBackbone.js comes to mind: https://backbonejs.org/docs/backbone.html https://backbonejs.org/docs/backbone.html. Edit: The author of backbone.js has a tool that generates documentation in this style. http://ashkenas.com/docco/ http://ashkenas.com/docco/
- NobodyNada 6y agoIt’s called literate programming, invented by Donald Knuth: https://en.m.wikipedia.org/wiki/Literate_programming https://en.m.wikipedia.org/wiki/Literate_programming
- momothereal 6y agoIn the 'real' Git, one of the functions I use frequently is `git checkout -- .`, which discards any unstaged changes. Looking at Gitlet's implementation, it wouldn't handle that well as `checkout` can only take a ref. So I guess I'm wondering what the real `git checkout -- .` actually does behind the scenes?
- ufo 6y agoFWIW, since Git 2.23 I prefer using "git switch" and "git restore" instead of "git checkout".
- 40four 6y agoThis is correct, ‘git restore’ is the way to do this in the current version of git. ‘checkout —-‘ still works, but the ‘help’ text in ‘git status’ now recommends using ‘restore’. Not only is it more semantic, it reduces the complexity of ‘git checkout’ which is a common complaint. Really, It doesn’t make much sense to tack on some random ’--‘ flag on ‘checkout’ for that functionality. ‘restore’ is clear and describes what it does.
- masklinn 6y ago> Not only is it more semantic, it reduces the complexity of ‘git checkout’ which is a common complaint. It doesn’t since the feature can’t be removed from git checkout for BC reasons.
- enricozb 6y agoThere is also Shit, a git implementation in an almost POSIX shell [0]. Not my software. [0]: https://git.sr.ht/~sircmpwn/shit https://git.sr.ht/~sircmpwn/shit
- baby 6y agoevery time I look at these custom git repository I'm confused as to how I can read the code. For inept people like me it's here: https://git.sr.ht/~sircmpwn/shit/tree https://git.sr.ht/~sircmpwn/shit/tree
- colejohnson66 6y agoThe term “tree” is pretty common in source control systems. So, for me, I just look for a link to the “tree”, which you managed to find. Just putting it out there for future readers.
- yewenjie 6y agoThere is also isomorphic-git. https://github.com/isomorphic-git/isomorphic-git https://github.com/isomorphic-git/isomorphic-git
- theknarf 6y agoI also recommend js-git (https://github.com/creationix/js-git https://github.com/creationix/js-git) if you need more low level control.
- Mistri 6y agoWe have a project at UC Berkeley for CS 61B (undergrad data structures) called "Gitlet", where we need to make a git implementation in Java. Was super fun! If you're curious: https://inst.eecs.berkeley.edu/~cs61b/sp20/materials/proj/proj3/index.html https://inst.eecs.berkeley.edu/~cs61b/sp20/materials/proj/pr...
- atum47 6y agoI once had to do some git stuff programmatic, back then I was working in python. I found out about this library called porcelain (I think it wasn't being maintained anymore). I end up having to go through the whole code so I can get some things done. Do not recommend. It is indeed a cool and helpful thing that you did. Congratulations.
- baby 6y agoSo, I'm going to put that out there, but I really wish I could read security-sensitive code like this. TLS implementations, cryptographic implementations, etc. It would be really amazing if there was a way for Github to automatically display code like this by extracting comments out. In general I think it's an amazing way of learning, I remember reading the gobyexample.com website and writing the same thing for go assembly: https://davidwong.fr/goasm/add https://davidwong.fr/goasm/add
- chungy 6y agoIt's a very old idea. Donald Knuth implemented it with both Pascal and C to promote an idea of "literate programming" -- you'd literally just write prose sprinkled with little bits of programming. On compilation, you can choose to compile either the documentation or program.
- someoldguy 6y agoFor an example, the PBRT book is great.
- WalterGR 6y agoPBRT is Physically Based Rendering: From Theory To Implementation by Matt Pharr, Wenzel Jakob, Greg Humphreys. https://www.pbrt.org https://www.pbrt.org https://www.pbr-book.org https://www.pbr-book.org https://www.amazon.com/Physically-Based-Rendering-Theory-Implementation/dp/0128006455 https://www.amazon.com/Physically-Based-Rendering-Theory-Imp...
- jonas21 6y ago> This book has deservedly won an Academy Award. I believe it should also be nominated for a Pulitzer Prize — Donald Knuth It's hard to beat that book review.
- truthr 6y agoThe deep learning library fastai uses this. Their source code is also their documentation. They use something called "nbdev" to accomplish this. And I have also seen other projects both related and unrelated to deep learning adopt it. This idea stems from Knuth.
- dang 6y agoDiscussed at the time: Gitlet: Git implemented in JavaScript - https://news.ycombinator.com/item?id=8931984 https://news.ycombinator.com/item?id=8931984 - Jan 2015 (66 comments) Also: Git implementation in 1k lines of Node.js - https://news.ycombinator.com/item?id=16453979 https://news.ycombinator.com/item?id=16453979 - Feb 2018 (2 comments)
- meetups323 6y agoThe format is nice, but I can't help but feel it'd be much easier for a human to parse as just normal TS with docstrings for flavor. For some of the more advanced functions, it's all but impossible to actually figure out what the input and return types are -- one must parse the english to find the references to "(see the module description for the format)", then try to figure out what that means, then go there, then repeat, until primitives are reached. Compare to TS where the return type is either right there in the code, or I can at least hover over the function to see a preview or Cmd+Click to get to the type definition itself. Not to mention the difficulty of manually keeping the english type descriptions in concert with the actual code -- some things computers are much better at than humans, verifying types is one of them. All that said, the flavor text is well written and I'm glad the author took the time to include it!
- nikital 6y agoGreat presentation! I created something similar — a step-by-step Git implementation that is designed for teaching Git internals: https://www.leshenko.net/p/ugit/ https://www.leshenko.net/p/ugit/
- leokennis 6y agoReading stuff like this makes me lose all hope to ever really understand (and being able to tame) git: > Under the covers, the pull command runs git merge FETCH_HEAD. This reads FETCH_HEAD, which shows that the master branch on the beta repository was the most recently fetched branch. It gets the commit object that alpha’s record of beta’s master is pointing at. This is the second commit. The master branch on alpha is pointing at the first commit, which is the ancestor of the second commit.
- deleted 6y ago[deleted]
- de_keyboard 6y agoI'd strongly suggest looking at https://github.com/isomorphic-git/isomorphic-git https://github.com/isomorphic-git/isomorphic-git It's a newer Git implementation but it has loads of features and it's easier to read than most. An excellent project.
- melenaos 6y agoAre these project for more or for browsers? I would love to been able to create wpa that could save on git without any backed. Is this possible with this or with isomorphic git?
- srathi 6y agoShameless similar plug: I recently implemented parts of git in Golang as a learning exercise. https://github.com/ssrathi/gogit https://github.com/ssrathi/gogit
- rognjen 6y agoTo people who're feeling like they are not able to understand or write something like this: While the author is definitely skilled, please know that you're looking at a finished project that took what looks like ~10 months of work. Do not compare what you know now with what the author has accomplished. They likely learnt a lot along the way and you would as well. If you're really keen to understand it start with the first commits: https://github.com/maryrosecook/gitlet/commits/master?after=ba49cd2ebf5cd89416cdde1eaab044f106bb45bc+965&branch=master https://github.com/maryrosecook/gitlet/commits/master?after=... The first two (meaningful) commits simply create the .git directory and the tests for it. You can almost certainly understand that.