69 comments

[ 2.9 ms ] story [ 139 ms ] thread
I wrote a short post about how and why I made Gitlet: http://maryrosecook.com/blog/post/introducing-gitlet
Keep making cool stuff. Loved your little lisp project!
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.
It's pretty awesome of you to provide the annotated source code for Gitlet! :D
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?

Well, the NetBSD kernel has been ported to JS: http://blog.netbsd.org/tnf/entry/kernel_drivers_compiled_to_...

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

My favorite emscripten demo was https://blog.mozilla.org/blog/2014/03/12/mozilla-and-epic-pr...

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

> 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?

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/

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.
It's just a different approach - sometimes understanding top-down is easier than bottom-up. The git code is pretty clean and simple, but pedagogically speaking it's not super easy to get an understanding of everything without reading most of it.

It's like reading a math paper where they define all the variables they use first before even getting to the main ideas. It's more rigorous, but not necessarily the most straightforward way to convey something.

Also, you don't necessarily always care that something is a struct or a union or that it's implemented as a custom variant of a B+tree that does xyz or that there's this quirk on Solaris that causes filenames to be written on disk backwards or something.

Author addresses this: "I went to the actual source to answer a few questions. But doing that was time consuming because I don’t know C well."

Also, the git source isn't the easiest code to follow.

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

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.)
i once took a leadership position at a small company that had a longtime contractor building one of their core web products out of foxpro. he refused to use any VCS, proclaiming that "version control is for the weak". needless to say, he didn't last very long.
He didn't last very long because he didn't agree with you?

'cos clearly whatever he was doing was acceptable up till that point.

There's no real opinion being given here. That would be like suggesting a general contractor on a new home was fired for difference of opinion, when the reason was he just didn't have insurance.
git checkout <branch>

where did my changes go?

They're still right where they were before you switched branches unless you've committed them before you switched branches, of course!
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?

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.

git checkout <branch> *

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

None of those changes will be lost or overwritten. So, no where?
Except that `checkout` makes the working copy match the target branch, which destroys the pending changes in the working copy, if a path is specified. It's the same as `revert` in other version control systems.
Nope. It stops and explicitly tells you "I cannot do that, because that would overwrite files X, Y and Z.".

Why would you think otherwise?

"If a path is specified," which is correct. The checkout command is like two commands in one.
Nobody ever accused the git command line UI of being user-friendly and well thought-out.
> 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.)

it's a learning curve alright.

(I'm not sure "if a path is specified" was actually part of the comment when I responded, but I'll grant that...)

Ah, missed that -- and I concur with the other commenter that this is bad UI.

However, I don't think this qualifies as particularly dangerous or surprising behavior. You're explicitly giving a file name after all -- you had better read up on what the command does if you're doing that. ("rm X" is pretty good precedent.)

(Self-reply and all, and I'm not sure anyone actually reads these old threads...)

Does "checkout -- some-file" not add an entry to the reflog?

(Which, btw, is one of the most important and useful commands ever in the history of VCS.)

that was my point, perhaps I could have made it clearer.

git checkout <commit-hash> <filename>

working copy of filename now gone if not committed.

You specified checking out a branch which is completely different than checking out a file by commit-hash.
of course you are correct. i am sorry. i was doing it from memory. you can leave out the commit-hash too, to get the same effect. not at a computer now but i think i remember "git checkout <commit-hash> * " being extra fun.

update, this is what i meant:

"git checkout * "

"git checkout <commit-hash> * "

"git checkout <branch> * "

each have the same warningless wipeout of uncommitted changes.

I think it's git in particular. Git can seem like it has more complexity than is necessary for a version control solution for some arbitrary "simple" project.
My favorite "how it works" article is The Git Parable

http://tom.preston-werner.com/2009/05/19/the-git-parable.htm...

My favorite Git tutorial is http://www.sbf5.com/~cduan/technical/git/

> you can only really use Git if you understand how Git works. Merely memorizing which commands you should run at what times will work in the short run, but it’s only a matter of time before you get stuck or, worse, break something.

(comment deleted)
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...
No need for websockets. Git has supported pushing and pulling via HTTP for many years.
You don't need git for that, simply save every keystroke made by the user.
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?)
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.
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!
how are files handled ?
What are the expected use cases?
One obvious use case is being able to edit files and have them saved to your git repo without leaving the browser.
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.

Its a great project to start with
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.
> One can't overestimate the gits value

I think you just did that.

In my world I haven't
(comment deleted)
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.