
Gitlet: Git implemented in JavaScript - fogus
http://gitlet.maryrosecook.com/
======
maryrosecook
I wrote a short post about how and why I made Gitlet:
[http://maryrosecook.com/blog/post/introducing-
gitlet](http://maryrosecook.com/blog/post/introducing-gitlet)

~~~
317070
I can't seem to find the rebase code? I've always wondered how that part
works. Great work otherwise! I've already taken a look at the three way merger
code.

~~~
ethomson
In a nutshell, it checks out the target and cherry-picks what had been HEAD
onto it, beginning at the merge-base.

[https://github.com/libgit2/libgit2/blob/master/src/rebase.c](https://github.com/libgit2/libgit2/blob/master/src/rebase.c)
may be helpful and (hopefully) readable.

------
Procrastes
I really liked your "Git in 600 words.[1]" I think it will help clear up some
confusion for some of my VCS wary colleagues.

1\. [http://maryrosecook.com/blog/post/git-in-six-hundred-
words](http://maryrosecook.com/blog/post/git-in-six-hundred-words)

~~~
throwawaymsft
Not to be rude, but I'm baffled why a professional programmer could be "wary"
of using a VCS. Or is it just git in particular? (More understandable, there's
a learning curve, but nearly every major project is using it. Git's proven
itself.)

~~~
throwawayaway
git checkout <branch>

where did my changes go?

~~~
knicholes
They're still right where they were before you switched branches unless you've
committed them before you switched branches, of course!

~~~
throwawayaway
mkdir commadir

cd commadir

git init

echo "dog" >> dog.txt

git add .

git commit -m one

echo "dog" >> dog.txt

git add .

git commit -m two

echo "dog" >> dog.txt

git log

git checkout dog.txt

cat dog.txt

how many dogs in dog.txt?

~~~
bryondowd
That isn't "git checkout <branch>", it is "git checkout <file>" If you try
checking out another branch while you have uncommitted changes, git will tell
you to commit or stash your changes before changing branch.

I can certainly understand the danger/confusion there, though. Using checkout
on a file reverts the file to a committed state. But the grandparent was
referring to checking out a branch, not a file, which is safe.

~~~
throwawayaway
git checkout <branch> *

has the same behaviour. does it not? I left out the asterisk as I was working
from memory.

------
patcoll
See also: [https://github.com/creationix/js-
git](https://github.com/creationix/js-git)

Kickstarter: [https://www.kickstarter.com/projects/creationix/js-
git](https://www.kickstarter.com/projects/creationix/js-git)

------
Sir_Cmpwn
I've asked GitHub to enable CORS for their https git endpoints, and I'm not
the first. Email them at support@github.com if you can think of some cool
stuff to do with that enabled.

------
zyxley
It would be interesting to see this baked into a browser-based text editor.
Make it fully client side and you can potentially save the git history in
localstorage and use it as an offline web app. I wonder if there are any git
servers that support websockets...

~~~
azeirah
You don't need git for that, simply save every keystroke made by the user.

~~~
WickyNilliams
Can't tell if you mean overwriting after every keystroke (if so, no history);
or saving a "fresh copy" after each keystroke (history, but terribly
inefficient - localStorage has space limitations); or saving a series of diffs
(how far do you have to go down that path before you realise you should have
just used git?)

------
filearts
This is a collossal effort and a huge community service. Thank you for being
so thorough in documenting your work. Even if others don't directly use your
code, you have given the world a great template to understand and implement
git!

------
skeoh
Some might also find js-git interesting: [https://github.com/creationix/js-
git](https://github.com/creationix/js-git)

~~~
isxek
Thanks for posting this. I remembered seeing a similar project before, but I
couldn't remember the name.

------
zrail
OT: I love the typography on your site, especially the little touches like the
decenders overlapping link underlines.

edit: after some research turns out the link underline styling is a Safari
thing. My point stands, though, the typography is wonderful.

------
caipre
> Sometimes, I can only understand something by implementing it. So, I wrote
> Gitlet, my own version of Git. I pored over tutorials. I read articles about
> internals. I tried to understand how API commands work by reading the docs,
> then gave up and ran hundreds of experiments on repositories and rummaged
> throught the .git directory to figure out the results.

When the source itself is available, why not just read the code? I understand
using articles and documentation to get the high to mid level view, but why
not go to the real source of truth if it's available?

~~~
nicholasjbs
I find reading the source of things can be incredibly helpful in some cases,
but when I want to really grok something, I need to write code myself. When
I'm just reading code it's easy to trick myself into thinking I understand
something, but it's much harder to do that if I have to make a piece of code
work correctly.

Peter Seibel wrote a great post on code reading, which hits on a similar
point: [http://www.gigamonkeys.com/code-
reading/](http://www.gigamonkeys.com/code-reading/)

~~~
caipre
I was referring more to the "ran hundreds of experiments" than the
"understanding by implementing." I agree wholeheartedly that actually making
something reveals far more about a problem/solution than would simply reading
about it.

------
hyp0
A related way to learn is from git's initial source, which was quite small.
[https://news.ycombinator.com/item?id=8650483](https://news.ycombinator.com/item?id=8650483)

Warning: the file format has changed slightly.

------
phatak-dev
Superb effort.

------
joelthelion
What are the expected use cases?

~~~
bmj
From TFA:

 _I wrote Gitlet to explain how Git works. I didn 't write it to be used. It
would be unwise to use Gitlet to version control your projects._

------
jokoon
how are files handled ?

------
nhlx2
Why JavaScript?

~~~
robotnoises
Atwood's law?

------
brianwillis
This is the most extreme example of Atwood's law that I've seen so far of.

Any volunteers for making an operating system kernel? Or has that been done
already?

~~~
icebraining
Well, the NetBSD kernel has been ported to JS:
[http://blog.netbsd.org/tnf/entry/kernel_drivers_compiled_to_...](http://blog.netbsd.org/tnf/entry/kernel_drivers_compiled_to_javascript)

It's using emscripten, not handwritten JS, though.

~~~
agumonkey
My favorite emscripten demo was
[https://blog.mozilla.org/blog/2014/03/12/mozilla-and-epic-
pr...](https://blog.mozilla.org/blog/2014/03/12/mozilla-and-epic-preview-
unreal-engine-4-running-in-firefox/)

It was really impressive to see UE4 running at ~7 fps on an old ThinkPad
(without discrete GPU) in pure software.

~~~
jcrites
Do you happen to have a link to the demo? I looked around but haven't been
able to find it.

It looks like the demo lived at the time at
[https://www.unrealengine.com/html5](https://www.unrealengine.com/html5) \-
and the site doesn't seem to work through Wayback Machine.

~~~
agumonkey
I randomly clicked on an URL Brendan Eich gave on twitter. Maybe this
[http://kripken.github.io/misc-js-
benchmarks/banana/benchmark...](http://kripken.github.io/misc-js-
benchmarks/banana/benchmark.html)

bbl

------
gitspirit
git is a tool that have to be introduced to as many as possible, even non-
developers. In essence git is a fundamental part of the future global world
collaboration. One can't overestimate the gits value.

~~~
eyko
> One can't overestimate the gits value

I think you just did that.

~~~
gitspirit
In my world I haven't

