News for hackers. Stuff that matters.
Re:Git koans by the_mitsuhiko on Monday April 08, 2013 @11:16AM (#5512185)
A lot of these are just plain wrong though or have a good reason and it makes me sad because I know Steve Losh uses a lot of Mercurial which I think has a much worse UI.

1. Silence: you can't alias built-in commands — for good reason. You don't change the defaults of commands, that's just going to cause problems with scripts. Why is it ignored silently? For starters because new git versions can add a command that would conflict with your config that came from an older version. You can trivially see that an alias is ignored by just adding ``--help`` to the command and it won't show you the alias.

2. One Thing Well: I fail to see the problem with that? All of these do the same thing. They check out a revision. With the exception of branch creation which is actually not a feature of `git checkout` but `git branch`. There is just a convenience operation on `git checkout` that also changes branches. The better question is why branches in mercurial are called bookmarks :P

3. Only the Gods: thankfully you don't know which branch something came from. Mercurial fucked me over more than once where I accidentally pulled a patch that came from a named branch that was conflicting with one I already had (you would not believe how many people name their branches "bugfix"). Mercurial's named branches are among the stupidest idea in software maintenance.

4. The Hobgoblin: these are all different commands. "How can I view a list of all tags": that's not what all tags is, that is "what's the list of tags I know locally". In mercurial you can't even figure that out properly because depending on the branch you're on you get different defined tags since tags are stored in the tree. Git's tag system is much superior to that.

"How can I view a list of all branches": that's a question you will never ask because it's the wrong question. A branch could show up multiple times. The correct question to ask is "How can I view a list of all local branches?" `git branch`, the second question is "how can I view a list of all remote branches?" And for that the answer is `git branch -r` or `git branch --remote` which makes a lot of sense in my mind.

"And how can I view the current branch": Same way you show all branches, just `git branch`. Shows you your current branch as well as all other branches and neatly colorizes it. `git rev-parse` is a command you really never have to use unless you script something.

Yeah, some could probably more consistent. The odd one out are `git submodule` and `git remote` which are sub commands instead of using parameters to remove/modify them. That being said, you rarely need to use those.

In direct comparison with hg, git's UI and functionality is a present from god. I'm pretty sure hg only has a better UI reputation because git's UI used to be pretty bad. Now however? Pretty sure it wins over hg hands down.

Re:Git koans by stevelosh on Monday April 08, 2013 @11:31AM (#5512301)
1. If a new version of git adds a command that shadows one of your aliases, you'd really prefer "git foo" to silently run the new command? That's better than telling you "hey this isn't going to do what you think any more"? Do you have `try: foo except: pass` in your Python code too? Come on. There's no reason git shouldn't at least warn you on stderr here.

2. `git checkout -- somefile.py` does not have anything to do with checking out a revision. It changes a file's contents, but doesn't change the parent of your working tree at all. Unlike `git checkout -b` which is inconsistent for convenience like you mentioned, the "make file x look like it was in rev y" function here is unique to git checkout as far as I can tell. Then again this is git, so there's probably at least four other ways to do this with cryptic plumbing commands.

3. I like Mercurial's named branches because I don't need to create a branch for every single commit. But even if you don't like them, the "record which branch X was made on" and "use that recorded information to group branches and such in the UI" are two different things. The second requires the first, but git could record which branch was checked out when each commit was made as some metadata in the commit, instead of dropping it on the floor. It would be a godsend when trying to figure out what actually happened during a merge.

4. `git branch` doesn't show you the current branch. It shows you all the local branches, with colors and padding spaces and asterisks and crap. What if you want the current branch in your prompt? Or just want to grab it in a script? Your choices are "pipe to grep and sed" or "use this ugly-ass rev-parse thing" instead of "git branch --current".

Git's UI is still abysmal. Mercurial preserves more data (branches), gives you the same power as Git and has a UI where "--help x", "-h x", "help x", "x -h", and "x --help" all do the same thing (pop quiz: how many different things does git do for those? hint: it's more than two).

Re:Git koans by the_mitsuhiko on Monday April 08, 2013 @12:23PM (#5512655)
> 1. If a new version of git adds a command that shadows one of your aliases, you'd really prefer "git foo" to silently run the new command?

Yes. Otherwise command line scripts will start doing horrible things. It was never intended that you can alias builtins, the only reason you might think you can is because it is allowed in mercurial which I think is a horrible idea.

> `git checkout -- somefile.py` does not have anything to do with checking out a revision.

Of course not. `git checkout` checks out things. You can check out a lot of things. Just because it works differently in hg does not mean it's wrong in git. git checkout does what it says on the tin: it checks out a branch or paths to the working tree.

> I like Mercurial's named branches because I don't need to create a branch for every single commit.

I think the concept of named branches in mercurial are hugely flawed and were the final nail in the coffin of why I migrated over to git. And I never looked back.

> What if you want the current branch in your prompt?

Then you use the underlying low-level commands or even better, you cat `.git/HEAD` which will be even faster. Not sure why for your prompt to look nice you need to have non-cryptic commands. Exactly for things like prompts there is the plumbing.

> gives you the same power as Git and has a UI where "--help x", "-h x", "help x", "x -h", and "x --help" all do the same thing

How is this different from mercurial? If anything mercurial has even more ways to show help: `man hg` which shows the manpage for all the builtin commands. `hg help` which shows a short version or `hg -v help` which shows a long version (which is not the man page). git only has two help pages: man pages for long and short text for short.

> gives you the same power as Git

I have yet to see this.

Re:Git koans by micampe on Monday April 08, 2013 @12:31PM (#5512704)
> Yes. Otherwise command line scripts will start doing horrible things. It was never intended that you can alias builtins, the only reason you might think you can is because it is allowed in mercurial which I think is a horrible idea.

You should understand what you are responding to before typing your answer.

Say today I create an alias “boom = <whatever>” and next week git introduces a boom command.

Now my alias is ignored, my scripts are broken and I might destroy my working copy or kill my cat by using it without knowing it now means something else.

Git gives some very stupid hints “branhc is not a git command, did you mean branch?” it should also warn me when I defined an invalid alias.

Maybe that alias was valid two versions ago or I just don’t know that command exists, since there are eleventy thousand of them.

Re:Git koans by the_mitsuhiko on Monday April 08, 2013 @12:46PM (#5512819)
> Now my alias is ignored, my scripts are broken and I might destroy my working copy or kill my cat by using it without knowing it now means something else.

Your scripts should not rely on aliases you have in your config. Scripts are intended to be used by different people.

Re:Git koans by micampe on Monday April 08, 2013 @01:07PM (#5512962)
I decide who is intended to use my scripts, thank you. I have many scripts where I am the only user.

Also, the issue of having an alias changing behavior without warning on my command line still exists.

Re:Git koans by salgernon on Monday April 08, 2013 @12:57PM (#5512888)
>> Git gives some very stupid hints “branhc is not a git command, did you mean branch?” it should also warn me when I defined an invalid alias.

This is the thing that really infuriates me - having a message from my tool that tells me there's an error is one thing, but offering a (frequently incorrect) correction forces me stop and try to figure out why this suggestion was offered, since it frequently has NOTHING to do with what I actually (mis)typed.

Lets put it this way - if this autocorrection feature is so great, then it should prompt you Y/N after giving the error message. Would it then be a better feature? Or would it make more people want to stab it in the eyeballs? Or if this suggestion feature is so great, then it should just DWIM in the first place.

Someone needs to take gits levenshtein algorithm away.

Re:Git koans by rson on Monday April 08, 2013 @03:11PM (#5513799)
> Or if this suggestion feature is so great, then it should just DWIM in the first place.

It can do this if you tell it do. The following tells git to wait 10 tenths of a second before executing the corrected command, giving you time to cancel if it is incorrect.

    git config --global help.autocorrect 10
Re:Git koans by stevelosh on Monday April 08, 2013 @12:34PM (#5512731)
If your solution to "get the current branch" is "cat out this magic data file that happens to exist in the data directory" then we have completely incompatible definitions of "user interface" and are never going to agree on this.
Re:Git koans by wonderzombie on Monday April 08, 2013 @12:54PM (#5512866)
The question was not how to just get the current branch, thought, right? As pointed out already, `git branch` does that.

The question was how to do it programmatically, and there are multiple ways to do it. You might still call that user interface, but it's that's a stretch; fancy shell magic like branch-in-prompt is typically write-once.

Re:Git koans by Anderkent on Monday April 08, 2013 @04:49PM (#5514492)
`git branch` doesnt do that. `git branch | less` followed by search might, if I remember some part of the branch name well enough to search for it.

Printing all the branches and having me scroll two screens up to find the one that's in color is not a solution to 'what branch am i on'

Re:Git koans by fr0sty on Tuesday April 09, 2013 @10:10AM (#5518106)
git branch gives you a nice asterisk too: $git branch * MyBranch NotMyBranch

It prints the branch as the first line of git status: $git status # On branch Foo ...

It also ships with a 'bash-competion' file which gives you a very simple way to disply the current branch (among other things) rather simply.

And of course you can also create your own alias if it is something you wish to do often.

Re:Git koans by philwelch on Tuesday April 09, 2013 @12:08PM (#5519061)
Why are you keeping hundreds of branches open at a time?
Re:Git koans by kyrias on Monday April 08, 2013 @04:13PM (#5514229)
If you want the branch in your prompt you should use the script that is shipped with git.
Re:Git koans by Anderkent on Monday April 08, 2013 @04:53PM (#5514524)
>I think the concept of named branches in mercurial are hugely flawed and were the final nail in the coffin of why I migrated over to git. And I never looked back.

How does having more information available ever hurt you?

Now, fair enough, the fact that mercurial expects branches to be unique might be annoying if you have the tendency to call all branches 'bugfix', but you seem to imply that simply having the branch name in which the commit was originally created as metadata on it would be somehow bad.

>git checkout does what it says on the tin: it checks out a branch or paths to the working tree.

'git checkout is good because checkout means the thing that git checkout does' riiiiight

Re:Git koans by wereHamster on Monday April 08, 2013 @12:29PM (#5512701)
`And how should I create a branch?. Use git checkout.` No. You create a branch with git branch. If you want to create a branch and immediately switch to it, use git branch (to create it) + git checkout (to switch to it). git checkout -b is just a shorthand for the two, it's there just for convenience. Unix has a lot of these occurrences. rm -rf as a shorthand for rm+rmdir, the open() syscall with O_CREAT shorthand for creat()+open() etc.
Re:Git koans by sirclueless on Monday April 08, 2013 @04:36PM (#5514390)
By the way, rm -rf does a lot more than rm+rmdir. You will probably learn this the hard way soon enough, unless you already know this and are just oversimplifying to show a point.
Re:Git koans by chrismorgan on Monday April 08, 2013 @12:07PM (#5512546)
Error, man page, short usage. And the arrangement doesn't make much sense.
Re:Git koans by DannyBee on Monday April 08, 2013 @03:39PM (#5513992)
It's interesting to watch people here defend git's interface as if it was all a very deliberate, intricate design that is well justified and thought out, when it very clearly grew organically. Not that there was "no" thought, but it's not like there is a huge poster on a wall in Junio's office (I checked) or the surrounding whiteboards, that have git UI principles that are being enforced on new commands/patches.

Basically, people are wrapping stuff up in justifications that didn't even exist when the commands came to be.

That doesn't make it bad, of course, but uh, retroactively justifying things is always a bit odd to watch.

I actually could care less about either git or mercurial; having helped write subversion, the majority of us were/are glad that we were replaced by not just one, but two things that people like more. The fact that it "destroyed" our software is irrelevant, Subversion made what we set out to make, something better than CVS, succeeded, and then the world got even better through git and hg.

The fact that git and hg proponents seem to simply enjoy fighting about which VCS is better/worse, rather than concentrating on making actual progress, is fascinating to me.

Re:Git koans by mpyne on Monday April 08, 2013 @06:06PM (#5514963)
> It's interesting to watch people here defend git's interface as if it was all a very deliberate, intricate design that is well justified and thought out, when it very clearly grew organically.

I don't see people doing too often, to be honest.

I do see git proponents saying that commands like git-checkout are misunderstood, but that isn't contradictory to "organic growth". From the beginning Linus was claiming that git was more of a content-addressable filesystem than an actual designed VCS.

If anything defenses like "git checkout -b is just shorthand for git branch && git checkout" are nothing but an acknowledgment of that organic growth. There's no reason to add a shorthand for a command sequence that no one uses.

Re:Git koans by j-kidd on Monday April 08, 2013 @07:10PM (#5515350)
Retroactively justifying things is what we always do. Here's an excerpt from Dan Ariely's "The (Honest) Truth About Dishonesty":

> The experience taught me that sometimes (perhaps often) we don't make choices based on our explicit preferences. Instead, we have a gut feeling about what we want, and we go through a process of mental gymnastics, applying all kinds of justifications to manipulate the criteria. That ways, we can get what we really want, but at the same time keep up the appearance -- to ourselves and to others -- that we are acting in accordance with our rational and well-reasoned preferences.

Simply replace all occurrence of "we" with "mercurial/git fanboys" based on your own preferences ;)

Re:Git koans by duncan_bayne on Monday April 08, 2013 @09:46PM (#5515988)
Thank you for Subversion :) Not only was it better than CVS but it was a damn site better than Visual SourceSafe too, which was often the alternative in Microsoft-land.
Re:Git koans by templaedhel on Monday April 08, 2013 @11:33AM (#5512316)
Your critique seems to be based off comparing git to mercurial and declaring that git is designed better. I don't think you're going to see a ton of disagreement with that in this community. You make good points too, with context a lot of those commands make more sense.

However well designed software shouldn't need the context. Well designed software is intuitive. We shouldn't need to know the intricacies in the git data model to able to understand the major commands and tools. As we begin to do more complex operations then more knowledge can be a prerequisite.

The fact that these commands all made sense with a detailed explanation is only a symptom of the problem, not an excuse.

Re:Git koans by ollysb on Monday April 08, 2013 @02:14PM (#5513459)
Normally I would agree with you that software should be intuitive with a minimum of learning. However git is only used by expert users, people who use it all day every day. There's no doubt that git has a bit of a steep learning curve but the abstraction you're forced to learn is really powerful. Having come from SVN the intuitive abstraction I was used to now seems woefully inadequate.
Re:Git koans by jamesgeck0 on Monday April 08, 2013 @05:31PM (#5514769)
I am an expert user. I've been using git almost every day for months. I've read about it's underlying data model and could write a tool that used it if I really needed to.

I _still_ have to use Google whenever I try to do anything with git that falls outside my normal workflow.

Re:Git koans by porker on Tuesday April 09, 2013 @04:13AM (#5516967)
Here Here! Same experience for me
Re:Git koans by elbear on Monday April 08, 2013 @05:43PM (#5514835)
What do you mean that git is used by expert users? Expert in what, git? If that is true, then I agree with you that you need to be an expert in git to be able to use it efficiently and not second guess yourself constantly when you come across a problem.

I agree that git's internal design is very well thought out. Its interface is very inconsistent though.

Re:Git koans by develop7 on Wednesday April 10, 2013 @04:08AM (#5523822)
> git is only used by expert users

1 235 026 expert users, my eye

Re:Git koans by aero142 on Monday April 08, 2013 @11:24AM (#5512251)
Ah, nothing like pointing out someone else's flaws to feel better about your own. Git is powerful but hard to learn and is often not intuitive. Knowing Hg also has issues doesn't help me when I'm trying to use git.
Re:Git koans by the_mitsuhiko on Monday April 08, 2013 @11:27AM (#5512277)
I just find it unfair criticism because hg has just as many UI kinks or just lack of UI to begin with. `hg diff` or how it's randomly split into different commands with a `-p` flag is just one example.
Re:Git koans by bvdbijl on Monday April 08, 2013 @11:33AM (#5512321)
Hg having kinks is not an excuse for git to have kinks too
Re:Git koans by w0utert on Monday April 08, 2013 @01:29PM (#5513100)
And, in addition to that, I find it very hard to believe that anyone who used both can sincerely say Hg's CLI interface is 'just as bad' as git's. I've used both and switched to git eventually, because from a technical point of view it's simply the better tool. Git is faster, more flexible, easier to deploy. The things it is not: more intuitive, easier, more consistent.

I don't understand why many git apologists continue to try to paper over the atrocious CLI that comes with git by blaming the user for not knowing his tools well enough. The tool is supposed to serve the user, not the other way around. Personally I think everything about the git CLI sucks, plain and simple. The command structure and naming, the switches, the error messages, the documentation, all of it. Compared to git, the hg CLI is a thing of beauty. Yet I still prefer git over Hg. No need to sugarcoat it and pretend git is flawless though.

Re:Git koans by thedufer on Tuesday April 09, 2013 @04:20PM (#5521038)
> Git is faster

This is a bold claim, and depends on a lot of variables. On very large repos, git is completely unusable.

Re:Git koans by giberson on Monday April 08, 2013 @11:32AM (#5512311)
Either you or I have misunderstood the article. These koans aren't criticism. They are stories meant to enlighten readers to lessons regarding git.

If you see each of these stories as criticism's about git, then you are the novice. Once you receive enlightenment on each story you will realize why each story is not criticism--you will see the error of the reasoning of the novice in the story and you will understand why Master Git's actions make sense.

Re:Git koans by GhotiFish on Monday April 08, 2013 @12:33PM (#5512725)
These really DO seem like criticisms. Particularly the hobgoblin. Given the context of the author[1] pointed out by the parent post, I think the thrust of these koans is obvious.

Personally It feels a bit dirty. I started out enjoying them, now they feel petty.

1. http://stevelosh.com/blog/ Scroll down. Mercurial everywhere.

Re:Git koans by npsimons on Monday April 08, 2013 @12:50PM (#5512845)
Yeah, about a third of the way through "Git Koans" I got the strong suspicion that the author was a Mercurial fan. It had potential and started out kind of amusing, but definitely felt like a bullied kid's fantasy near the end. Shame, too, as many of the author's other posts seem very well written and insightful. Eh, nobody's perfect.
Re:Git koans by imissmyjuno on Monday April 08, 2013 @11:36AM (#5512339)
Surely you can't say that about `git branch -d` vs. `git rm` and other puzzling inconsistencies.
Re:Git koans by giberson on Monday April 08, 2013 @11:45AM (#5512400)
Yes I can, and am. As pointed out elsewhere, the commands are named for what they do not necessarily for how you would use them.
Re:Git koans by imissmyjuno on Monday April 08, 2013 @04:44PM (#5514455)
Which is terrible UI. I don't think we're disagreeing so much as diverging on the definition of what constitutes an issue here.
Re:Git koans by encoderer on Monday April 08, 2013 @12:06PM (#5512537)
Your bookmarks swipe, I don't get it?

Branches in mercurial are called Named Branches. And they have the benefit that commits made in the branch will always know where they were created.

They have Bookmarks which really are a better name than "git branches" anyway because you can't really understand branching in Git until you understand that a branch name is just a pointer--a bookmark if you will--to a specific HEAD commit.

Re:Git koans by ajanuary on Monday April 08, 2013 @11:24AM (#5512255)
> There is just a convenience operation on `git checkout` that also changes branches.

Isn't that violating 'doing one thing'? (Your other examples in this point are valid, and serve to show how powerful building concepts on top of a few primitives can be, if confusing at times)

Re:Git koans by nazri1 on Monday April 08, 2013 @11:33AM (#5512318)
Here's how I view the checkout command: It is used to check out stuff from your git database into your working tree. Stuff here means either the whole tree or some files in it. You can check out a whole tree (branch) by specifying its sha1, or you can check out a single file by specifying the tree and the filename. The fact that checkout can be used to create a branch is just a convenience because most of the time it's easier to give the tree sha1 a name to refer to for further git commands.
Re:Git koans by Aga on Monday April 08, 2013 @07:08PM (#5515341)
This is exactly what I tell students in my Git courses during the first hour.

Git checkout is a command to read something from your .git-folder to your working directory.

Especially for people coming from ClearCase, the concept of Git checkout needs to be clarified as fast as possible. (In CC checkout means you make an element (file) editable for you, and possibly reserve it to you too)

Re:Git koans by the_mitsuhiko on Monday April 08, 2013 @11:26AM (#5512271)
> Isn't that violating 'doing one thing'?

Yes. But that violation would also be there if `git branch` would checkout. And in that sense, what's more odd "git checkout -b new-branch" or "git branch --checkout new-branch"?