News for hackers. Stuff that matters.
Re:Shit – An implementation of Git using POSIX shell by ddevault on Tuesday February 11, 2020 @07:12PM (#22304416)
Hiya HN. I was ranting on Mastodon earlier today because I feel like people learn git the wrong way - from the outside in, instead of the inside out. I reasoned that git internals are pretty simple and easy to understand, and that the supposedly obtuse interface makes a lot more sense when you approach it with an understanding of the fundamentals in hand. I said that the internals were so simple that you could implement a workable version of git using only shell scripts inside of an afternoon. So I wrapped up what I was working on and set out to prove it.

Five hours later, it had turned into less of a simple explanation of "look how simple these primitives are, we can create them with only a dozen lines of shell scripting!" and more into "oh fuck, I didn't realize that the git index is a binary file format". Then it became a personal challenge to try and make it work anyway, despite POSIX shell scripts clearly being totally unsuitable for manipulating that kind of data.

Anyway, this is awful, don't use it for anything, don't read the code, don't look at it, just don't.

Re:Shit – An implementation of Git using POSIX shell by wkjagt on Tuesday February 11, 2020 @08:25PM (#22304841)
> instead of the inside out

Now the name makes even more sense. I first read it as sh/git, but reading it as something that starts inside and slowly works its way out is now my preferred explanation of the name.

Re:Shit – An implementation of Git using POSIX shell by orthoxerox on Wednesday February 12, 2020 @01:18AM (#22306334)
I am simultaneously revolted and fascinated with the brilliance of your explanation.
Re:Shit – An implementation of Git using POSIX shell by sbergot on Wednesday February 12, 2020 @03:17AM (#22306918)
The name also plays well with the porcelain & plumbing metaphores of git.
Re:Shit – An implementation of Git using POSIX shell by hyperpallium on Wednesday February 12, 2020 @04:29AM (#22307322)
metaphors. Not being pedantic, it just puzzled me a while to see what was wrong with that word.
Re:Shit – An implementation of Git using POSIX shell by fouc on Wednesday February 12, 2020 @05:14AM (#22307559)
what do you get when you cross a metaphor and a semaphore? a metaphore
Re:Shit – An implementation of Git using POSIX shell by majewsky on Wednesday February 12, 2020 @06:00AM (#22307796)
So it's a metaphor that only a limited amount of people can use at any given time?
Re:Shit – An implementation of Git using POSIX shell by maw on Wednesday February 12, 2020 @11:33AM (#22310217)
I never sem a phore that I didn't like.

¿

Re:Shit – An implementation of Git using POSIX shell by brian_herman__ on Wednesday February 12, 2020 @12:59PM (#22311013)
lol
Re:Shit – An implementation of Git using POSIX shell by D-Coder on Wednesday February 12, 2020 @09:48PM (#22314920)
A semi-metaphor?
Re:Shit – An implementation of Git using POSIX shell by thih9 on Wednesday February 12, 2020 @02:49AM (#22306779)
This comment looks like an offtopic pun to me and feels distracting.
Re:Shit – An implementation of Git using POSIX shell by blub on Wednesday February 12, 2020 @02:45AM (#22306762)
If it's so hard to learn about this tool and so easy to learn about it the wrong way, that's a pretty obvious hint that there's something wrong with the tool.

Having to learn about the internals is a giveaway that the tool suffers from poor encapsulation.

To me git is definitely one of those tools where one should satisfice and not learn it deeply, because it's not worth the effort. One can successfully stick to a simple workflow and ignore anything git astronauts come up with, like git flow if they want to keep their sanity and focus on what matters - creating quality software. And almost any team has some git fetishist which will be thrilled to help when things go south. And if they don't, it's probably for the better.

Re:Shit – An implementation of Git using POSIX shell by TeMPOraL on Wednesday February 12, 2020 @04:23AM (#22307280)
> If it's so hard to learn about this tool and so easy to learn about it the wrong way, that's a pretty obvious hint that there's something wrong with the tool.

Not necessarily. This may mean (and I think in this case, it does) that people are too afraid to learn about those "internals" - or should I say, the mental model behind the tool (and then some of those people write tutorials for others, perpetuating the problem). And with a "monkey see, monkey do" approach, people can fail at anything, up to and including tying their own shoelaces.

There is no such thing as a perfect encapsulation. Not in programming, and especially not in the physical world. "Internals" are ever-present and leak into view all the time. A good abstraction is just one that you can use day-to-day without constantly minding what's going on behind the scenes.

More importantly though, when you're just learning a bunch of git commands in isolation ("monkey see, monkey do"), you're not learning a tool/an abstraction - you're just learning its interface. That's sometimes OK, but in general, for effective use of an abstraction it's better to learn what moving pieces it is abstracting away. Which in case of Git is that it's a DAG. DAGs are kind of fundamental in programming, too; it's good to understand them.

Re:Shit – An implementation of Git using POSIX shell by JoeAltmaier on Wednesday February 12, 2020 @08:46AM (#22308736)
Its part of a bigger issue - source control tools have wildly different fundamental models. Moving to git from anything else will be confusing, because users jump to conclusion about what commands and operations are doing. Its different from other tools in important ways.
Re:Shit – An implementation of Git using POSIX shell by huherto on Wednesday February 12, 2020 @10:49AM (#22309768)
I moved from SCCS to RCS to CVS to Subversion to Git.

Moving to Git was the more difficult step for me. I prefer it now. For a while I had to move back to Subversion and I hated it.

Re:Shit – An implementation of Git using POSIX shell by touisteur on Thursday February 13, 2020 @01:34AM (#22315776)
Can't use svn for the life of me, though I used it for 10 years before trying git for a real dvcs need (remote team for a while)...

Just the idea pains me. Missing git add -p, cherry-pick & rebase -i so much I immediately put git-svn on if I have to go back...

Also, it makes telecommuting easier, asynchronous team work so much simpler...

I think the key 'abstraction' that people don't understand is cherry-pick. I can't explain clearly in fine details /how/ it works, but it is the base of so much of git's power...

Re:Shit – An implementation of Git using POSIX shell by blub on Saturday February 15, 2020 @03:15PM (#22337666)
Monkey see, monkey do would be watching someone use git and imitating them. Reading the manual or an overview of the commands and using them is how learning new tools typically works.

It should be possible to learn the commands for creating a branch, uploading our changes or making a commit like it was/is possible for all version control tools and then move on with our professional lives, which likely revolve around writing software and not fumbling with git.

By the way, I love your conversation about Merkle trees below; it was one of the most surreal things I've read lately. :-)

Re:Shit – An implementation of Git using POSIX shell by TeMPOraL on Sunday February 16, 2020 @03:36AM (#22340576)
> It should be possible to learn the commands for creating a branch, uploading our changes or making a commit like it was/is possible for all version control tools

The problem revolves around the fact that, despite same name being used, git!branch != svn!branch, git!commit != svn!commit, etc. They serve related purposes - but not the same, because the concepts behind them are different. Learning a tool means learning those concepts. So in the process of learning "git commit" and "git branch", you're supposed to pick up on the "pointer to a node in a DAG" thing - otherwise you haven't learned "git commit", you've learned something else that's vaguely similar. And then you'll have difficulties when its behavior goes against your expectations.

Re:Shit – An implementation of Git using POSIX shell by blub on Sunday February 16, 2020 @04:38AM (#22340750)
But they behave pretty darn close to SVN branches and commits and... they're also called branches and commits. It's clear why that happened - no one would have used a weird tool which turned the old concepts on their heads, so git was being taught based on comparisons with existing tools.

Now that git's very popular, the teachers have become arrogant and are claiming that our mental models for how VCS work are wrong and we should instead adapt our thinking to the git internals. In almost all other professions a confusing tool is scorned, but only developers are expected to learn how all sorts of weird contraptions work and then anyone who can't keep up is scorned instead.

git is almost 15 years old and here we have yet another attempt at clarifying how it works to the masses. Why are there so many git GUIs and tutorials and attempts to clarify how this tool works? It's a freaking VCS, not rocket science. git took something that used to be straightforward and doable by any developer and turned it into an over-complicated mess.

Now here's a question for you: why do you defend this anti-developer tool instead of siding with fellow developers?

Re:Shit – An implementation of Git using POSIX shell by xmodem on Wednesday February 12, 2020 @07:42AM (#22308344)
> There is no such thing as a perfect encapsulation.

It's a logical fallacy to use this as an excuse for a tool having bad encapsulation/abstraction.

Yes it's impossible to have a perfect abstraction. No that doesn't mean we shouldn't try harder.

Re:Shit – An implementation of Git using POSIX shell by navaati on Wednesday February 12, 2020 @08:02AM (#22308428)
Completely agree.

> Which in case of Git is that it's a DAG

And one step beyond that, that it's a Merkel tree. It's key to understanding stuff like "if I change a commit, it changes all commit after that" or "if I move (cherry pick, rebase) this commit, I'm creating a new one, not really moving".

Re:Shit – An implementation of Git using POSIX shell by ilammy on Wednesday February 12, 2020 @12:22PM (#22310653)
> And one step beyond that, that it's a Merkel tree.

Not really, not every block chain is a Merkle tree. Since Git history is not linear, you can’t order the commits in any canonical way. You definitely can order them in some way (like "git log" does) and then construct a tree for that list of hashes, but this is not really useful computation. Git repo integrity is verified simply by HEAD commit hash because you normally clone the entire repository anyway.

Re:Shit – An implementation of Git using POSIX shell by TeMPOraL on Wednesday February 12, 2020 @01:13PM (#22311146)
Is git even a Merkle tree? Git history forms a DAG, not a tree. But I'm not 100% sure about how the hashes are computed - whether they work on the DAG, or on some local subtree.
Re:Shit – An implementation of Git using POSIX shell by ilammy on Wednesday February 12, 2020 @04:09PM (#22312839)
No, it’s not. Commit hashes are exactly what it says on the tin: hash sums of commit objects, which are basically text files that include hash sums of tree objects (directory tree state), hash sums of parent commits, your commit message and other metadata. You can see it with "git cat-file":

    $ git cat-file -p d8defd0bb0062ed541de173a2aec834b64d6adbe
    tree cbdb56fe9bb1766d8fc2b2e53c9c934efbacbf1c
    parent a8a1049c06d100a3f926a82414e6addb9b9af5e8
    author ilammy <[email protected]> 1581533224 +0200
    committer ilammy <[email protected]> 1581533224 +0200
    
    fixup! Avoid unsigned overflow in length computations
And compute the commit hash manually to verify that:

    $ sha=d8defd0bb0062ed541de173a2aec834b64d6adbe
    $ cat <(echo -ne "$(git cat-file -t $sha) $(git cat-file -s $sha)\0") \
          <(git cat-file -p $sha) | sha1sum
    d8defd0bb0062ed541de173a2aec834b64d6adbe  -
Git prefixes object content with object type ("commit" in case of commits), its size in bytes (textual, decimal), terminated by a null byte. And hashes all of that get the commit hash.
Re:Shit – An implementation of Git using POSIX shell by 2zcon on Wednesday February 12, 2020 @06:09AM (#22307832)
>that's a pretty obvious hint that there's something wrong with the tool.

Or that the problem space is inherently difficult.

Re:Shit – An implementation of Git using POSIX shell by wyclif on Wednesday February 12, 2020 @10:58PM (#22315220)
Almost everybody I've ever worked with who complained about Git has a conversation with a coworker that goes something like this:

Coworker: "I really hate Git, it's so hard to understand what's going on internally."

Git guy: "Did you read the documentation?"

Coworker: "Nope."

Git guy: "Did you read Git - book?"

Coworker: "Nope."

Git guy: "Did you read Scott Chacon's 'Pro Git'?"

Coworker: "Nope."

Git guy: "..."

Re:Shit – An implementation of Git using POSIX shell by blub on Saturday February 15, 2020 @03:06PM (#22337610)
That conversation already went off the tracks at "internally", since it shouldn't matter at all how it works internally. We do not learn how most things work in detail, because we wouldn't have time to live our life if we did.

In this particular case, git is a version control tool and it supports various typical operations for such tools. One should be able to learn the commands and then successfully use the tool. If that's not possible, I continue to assert that there's a problem with the tool.

Re:Shit – An implementation of Git using POSIX shell by Ace17 on Thursday February 13, 2020 @02:25AM (#22315975)
The likelihood for this conversation to occur, in a way, also depends on the tool itself, and tells us something about it.

As a matter of fact, git is hard to use.

The question is: keeping the same level of functionality, could it have been made easy to use?

Re:Shit – An implementation of Git using POSIX shell by p_l on Thursday February 13, 2020 @05:51AM (#22316737)
It also speaks about the quality of users as a whole - we somehow forgot to RTFM at all or lead people to documentations, simultaneously accepting lack of documentation in a vicious cycle.
Re:Shit – An implementation of Git using POSIX shell by amenod on Thursday February 13, 2020 @02:26PM (#22320586)
And the answer is: yes, absolutely. Mercurial is a whole level better. Unfortunately git won - because of GitHub, not on technical merit.
Re:Shit – An implementation of Git using POSIX shell by chx on Tuesday February 11, 2020 @07:53PM (#22304678)
> the supposedly obtuse interface makes a lot more sense when you approach it with an understanding of the fundamentals in hand.

Agreed. I always said the best git tutorial is https://www.sbf5.com/~cduan/technical/git/

> The conclusion I draw from this is that 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.

Re:Shit – An implementation of Git using POSIX shell by chenhan on Tuesday February 11, 2020 @09:57PM (#22305318)
I never really understood Git until I read this tutorial: https://github.com/susam/gitpr

Things began to click for me as soon as I read this in its intro section:

> Beginners to this workflow should always remember that a Git branch is not a container of commits, but rather a lightweight moving pointer that points to a commit in the commit history.

    A---B---C
            ↑
         (master)
> When a new commit is made in a branch, its branch pointer simply moves to point to the last commit in the branch.

    A---B---C---D
                ↑
             (master)
> A branch is merely a pointer to the tip of a series of commits. With this little thing in mind, seemingly complex operations like rebase and fast-forward merges become easy to understand and use.

This "moving pointer" model of Git branches led me to instant enlightenment. Now I can apply this model to other complicated operations too like conflict resolution during rebase, interactive rebase, force pushes, etc.

If I had to select a single most important concept in Git, I would say it is this: "A branch is merely a pointer to the tip of a series of commits."

Re:Shit – An implementation of Git using POSIX shell by Izkata on Tuesday February 11, 2020 @11:58PM (#22305929)
And you can see this structure if you add to any "git log" command "--graph --oneline --decorate --color". IIRC some of those are unnecessary in recent versions of git, I just remember needing all of them at the point I started using it regularly.

I have a bash function for it (with a ton of other customizations, but it boils down to this):

  function pwlog() {
    git log "$@" --graph --oneline --decorate --color | less -SEXIER
  }
  pwlog --all -20
(...in that "less" command, "S" truncates instead of wraps lines, one "E" exits at EOF, "X" prevents screen-clearing, and "R" is to keep the color output. The second "E" does nothing special, it and "I" (case-insensitive search) are just to complete the word)
Re:Shit – An implementation of Git using POSIX shell by westurner on Wednesday February 12, 2020 @04:36PM (#22313054)
You can also set $GIT_PAGER/core.pager/$PAGER and create an alias to accomplish this:

  #export PAGER='less -SEXIER'
  #export GIT_PAGER='less -SEXIER'
  git config --global core.pager 'less -SEXIER'
  git config --global alias.l 'log --graph --oneline --decorate --color'
  # git diff ~/.gitconfig
  git l
core.pager: https://git-scm.com/docs/git-config#Documentation/git-config...

> The order of preference is the $GIT_PAGER environment variable, then core.pager configuration, then $PAGER, and then the default chosen at compile time (usually less).

Re:Shit – An implementation of Git using POSIX shell by gruez on Tuesday February 11, 2020 @11:50PM (#22305896)
>This "moving pointer" model of Git branches led me to instant enlightenment.

As opposed to any other VCS? Feels like that model is the only one that works with SVN too. I struggle to see how "branch is a container of commits" is a viable model to begin with.

Re:Shit – An implementation of Git using POSIX shell by Izkata on Wednesday February 12, 2020 @12:01AM (#22305942)
It's a good-enough description of SVN, where branches exist in the same directory tree, commits are tied to the branch by way of the path, and the merge tools are "merge this batch of commits from branch A to trunk" (you don't have to take the whole branch at once).

One of the biggest hurdles my co-workers have had learning git after having used svn for years is the "bucket of commits" mental model they've built up for branches. A common question is how to merge a single commit.

Re:Shit – An implementation of Git using POSIX shell by rileymat2 on Wednesday February 12, 2020 @12:07AM (#22305969)
This is closer to how I would describe HG and SVN. Branches can be traced from start to merge, they are heavy. You know which commits came from what.

In git you can lose track of what came from what branch when you start merging multiple back and forth, this does happen with svn.

Re:Shit – An implementation of Git using POSIX shell by Mikhail_Edoshin on Wednesday February 19, 2020 @03:26PM (#22369684)
Mercurial branches are different from git branches; they're topological structures that emerge when a revision gets an alternate child. They're like growing and stopping lines of development. They exist on their own, Mercurial simply allows to give them names. What git calls branches in Mercurial is called bookmarks.
Re:Shit – An implementation of Git using POSIX shell by phodge on Tuesday February 11, 2020 @10:54PM (#22305580)
> A branch is merely a pointer to the tip of a series of commits.

But this is not actually correct because a branch can often point to a commit that is not the tip.

Re:Shit – An implementation of Git using POSIX shell by kortilla on Tuesday February 11, 2020 @11:44PM (#22305877)
It is the tip for that branch. Even if there exist other commits building on the commit the current branch points to, the pointer is still at the tip for that branch.

The point is that a branch is simply a pointer to a commit that automatically encapsulates all of the parent commits.

Re:Shit – An implementation of Git using POSIX shell by jbnorth on Tuesday February 11, 2020 @11:12PM (#22305692)
I think I see what it means though. The branch uses that commit as a new tip to then branch off of, not necessarily meaning a new branch starts at the existing 'tip'.
Re:Shit – An implementation of Git using POSIX shell by na85 on Tuesday February 11, 2020 @08:05PM (#22304735)
>The conclusion I draw from this is that you can only really use Git if you understand how Git works.

I say this as someone who uses git regularly, and who prefers it to all other version control systems I have tried:

A tool that breaks the principle of encapsulation by forcing you to grok its internals if you are to have any hope of understanding its arcane and inconsistent usage syntax is frankly not a very good tool.

By contrast, I don't understand how vim works beyond the base conceptual level (keypress goes in, character shows up on screen or command is executed) and yet I don't have any trouble using it. I don't need to know vim's internals to use it effectively. Vim is a good tool.

Re:Shit – An implementation of Git using POSIX shell by kragen on Tuesday February 11, 2020 @09:33PM (#22305205)
> I don't understand how vim works beyond the base conceptual level

How much time have you spent trying to figure out how to change the font size in Vim, rotate text 90° in Vim, recalculate a formula in Vim, or insert an image into a document you're editing in it? If the answer is “none”, you probably have a pretty deep understanding of the data model Vim manipulates, even if you aren't aware of it.

Re:Shit – An implementation of Git using POSIX shell by hurrrrrrrr on Wednesday February 12, 2020 @11:39AM (#22310274)
On the other hand I understand de data model of git and can't to the most basic shit without looking up which invocation I need via search engine/man pages. Like... deleting a branch `git branch -d` (-D for forced deletion). Deleting a remote? `git remote rm`. Knowing the model teaches me nothing about the ui.
Re:Shit – An implementation of Git using POSIX shell by war1025 on Wednesday February 12, 2020 @12:49PM (#22310911)
This seems like a good opportunity to plug two aliases I wrote about a year ago that have been very helpful for cleaning up all the extraneous branches that would show up when I ran `git branch`.

I run `git listdead` after I merge and delete a branch and do the next fetch (`git pull --rebase`). That lists the branches that can now be deleted.

Then I run `git prunedead` and it actually removes them.

Previously if I ran `git branch` it would list every development branch I had ever created in nearly a decade of work. Now it lists maybe ten branches.

   listdead = "!sh -c \"git branch -vv | grep ': gone]' | awk '{print \\$1}'\""

   prunedead = "!sh -c \"git branch -vv | grep ': gone]' | awk '{print \\$1}' | xargs git branch -D\""
Re:Shit – An implementation of Git using POSIX shell by kragen on Wednesday February 12, 2020 @02:16PM (#22311789)
Myself, I frequently refer to the man pages, as well as StackOverflow.
Re:Shit – An implementation of Git using POSIX shell by oblio on Wednesday February 12, 2020 @07:18AM (#22308197)
> rotate text 90° in Vim, recalculate a formula in Vim, or insert an image into a document you're editing in it

I'm not sure if I'm missing some features in Vim or you're actually pulling my leg by forcing me to notice that I know more about text than I care to admin :-)

(I'm not OP, BTW, just a random passer-by)

Re:Shit – An implementation of Git using POSIX shell by kragen on Wednesday February 12, 2020 @11:19AM (#22310081)
The latter! Sorry, didn't mean to cause you to question your sanity.
Re:Shit – An implementation of Git using POSIX shell by anoncake on Tuesday February 11, 2020 @08:56PM (#22305045)
Using Vim requires you to understand how the data it operates on is structured. The same applies to Git. Plain text is just a lot simpler than a VCS repository.
Re:Shit – An implementation of Git using POSIX shell by IcePic on Wednesday February 12, 2020 @02:58AM (#22306827)
But you can use your awesome vim skill to feed text into a OpenOffice document, and while the OOo internals are probably 100x more complicated than vim, the user interface for "text on my screen" stays the same, and transition is smooth, even though the internals underneath is vastly different. If git requires 'everyone' to know the internals before they can use it, as opposed to rcs,cvs,svn,perforce users who can more easily flip around between those for most basic usages, then its on git for having a complicated shell around a complicated set of internals.

It would have been nice if there was a simpler shell around the complex machinery for those (us?) who don't want to do crazy stuff, who don't need to be able to do crazy stuff and who could settle for only the simple 90% of the tooling like we do with the alternatives, but are forced to use git for external reasons.

Re:Shit – An implementation of Git using POSIX shell by wruza on Wednesday February 12, 2020 @03:08AM (#22306872)
Plain text is internally ropes-something, indented with meters of vimscript, colored with a syntax model that is okay to change, hard to create from scratch, etc. it’s all hidden from a regular user who uses a subset of all features.

But if you ignore the non-ms movement, shortcuts and advanced transforms, it is still a text editor that everyone may use. You can’t put your text (text, not a current mode!) into a state that looks okay but requires a vim guru to continue or start over because something is broken in the model. That’s different from git issues where working copy looks okay, but the branch and merge are broken in subtle ways.

>Plain text is just a lot simpler than a VCS repository.

Than a Git repository, not a VCS one. Not saying that VCS = plain text, but much simpler models exist for merging teh codes.

Re:Shit – An implementation of Git using POSIX shell by emacdona on Tuesday February 11, 2020 @08:07PM (#22304741)
Scott Chacon wrote a book on git internals that was published by peepcode some time ago. Searching for where to buy it turned up this HN thread: https://news.ycombinator.com/item?id=7999515

Looks like peepcode was acquired, but the book was open sourced: https://github.com/pluralsight/git-internals-pdf

I'm reading through it now. It starts with the fundamental git structure and works up from there.

Re:Shit – An implementation of Git using POSIX shell by jasode on Wednesday February 12, 2020 @06:15AM (#22307867)
>I reasoned that git internals are pretty simple and easy to understand, and that the supposedly obtuse interface makes a lot more sense when you approach it with an understanding of the fundamentals in hand.

Everybody's brain is different but I actually understand all of git's internals (the "plumbing") but it doesn't help me with the git commands (the "porcelain").

Yes, I know that git is a DAG (Directed Acyclic Graph), and that HEAD is a pointer, and the file format of BLOBs and SHAs, etc. If I were to implement a DVCS, I would inevitably end up reinventing many of the same technical architecture decisions that Linus came up with. But none of that insider knowledge really helps me remember git syntax if I haven't been using it in more than a month. Even though I grok git's mental model, I still can't answer the top-voted "git" questions on Stackoverflow without a cheat sheet: https://stackoverflow.com/questions/tagged/git?tab=Votes

The git UI and unintuitive syntax is just too hard for me to remember unless I use it every day.

In contrast... In vi or MS Word, I can effectively modify text without digging into underlying "rope data structure"[1]. In databases & SQL, I can "INSERT INTO x" without learning the "internals" of b-trees[2]. In Photoshop, I can stack layers without learning the math "plumbing" of alpha blending[3]. And yet for some reason, Git in particular needs people to learn it "inside out" more so than other tools. Not sure why Git needs this cognitive prerequisite.

[1] https://en.wikipedia.org/wiki/Rope_(data_structure)

[2] https://en.wikipedia.org/wiki/B-tree#B-tree_usage_in_databas...

[3] https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blendi...

Re:Shit – An implementation of Git using POSIX shell by cormacrelf on Wednesday February 12, 2020 @06:30AM (#22307947)
Unfortunately, I think you have to learn this way because everyone who came before you also did. So not only is the porcelain oriented towards this understanding, but so are people's existing repositories and workflows.

People regularly use the limited subset of git that Github permits without learning how it works internally. If only the 'edit this file' button were powerful enough to do actual work... It isn't, and that's the other problem: internals knowledge actually helps you do day-to-day versioning tasks. The reality is that one day two developers will submit PRs that conflict, and you'll have to find a way to merge them both, and knowing how rebasing works inside absolutely helps you. The analogy is more MSWord style-stacking than manipulating ropes directly, because Git does manage to completely hide some of its guts. (Object storage, compression, transfer come to mind.)

Re:Shit – An implementation of Git using POSIX shell by stefco_ on Wednesday February 12, 2020 @12:25PM (#22310691)
Though git's interface is highly flawed, I do think a good VCS needs to expose more of its storage model to the user (or at least a model isomorphic to it) than most apps.

In vi and Word, you're not worried about state changes outside of saving the current state and, possibly, undoing some number of steps. In a VCS, you might need to check out, merge, or compare arbitrary states from the history, and doing this inherently requires a deeper understanding of how the history is stored. A good VCS should expose these internals in a clear way. In my experience, working with even 1 teammate immediately requires you to have some mental model of how your VCS deals with merging different histories.

That said, it's up to the VCS's interface to make these things clear. Git's mental model is simple enough, and the porcelain can do some of this stuff very well, but CLI is arcane; I end up storing extremely common functions as shortcuts because I'd never remember them or want to type them even though I use them dozens of times a day.

Re:Shit – An implementation of Git using POSIX shell by Nullabillity on Thursday February 13, 2020 @01:36PM (#22320121)
> In databases & SQL, I can "INSERT INTO x" without learning the "internals" of b-trees[2].

True, but it is very helpful when designing your indexes.

Re:Shit – An implementation of Git using POSIX shell by ssivark on Tuesday February 11, 2020 @08:26PM (#22304850)
> oh fuck, I didn't realize that the git index is a binary file format

I wonder if the project (or likely, another one) might be better served by implementing the index using plain text (or whatever else might be more natural for shell wrangling) to elucidate the conceptual structure rather than matching git literally.

PS: The name is very apropos. One doesn’t see too many such fitting opportunities — feels warm and fuzzy to see this one well used :-)

Re:Shit – An implementation of Git using POSIX shell by viraptor on Tuesday February 11, 2020 @07:26PM (#22304504)
> I feel like people learn git the wrong way

Why do you think it's the wrong way? I sit somewhere in between and think that some people want to know the details and learning from inside is a good idea. But some other people want to simply be users and for the tool to get out of their way - and that's also good. So if the docs or the UX make either way hard or less effective, that's on the docs or the UX to improve.

Re:Shit – An implementation of Git using POSIX shell by ddevault on Tuesday February 11, 2020 @07:27PM (#22304513)
You'll use git a hundred times a day, every day, for the rest of your career. It's easily worth the hour it'll take to learn it properly.
Re:Shit – An implementation of Git using POSIX shell by viraptor on Tuesday February 11, 2020 @08:04PM (#22304728)
Sure, but I also use a mouse. I could learn how the optical mouse works. I have some guesses about it too, but never actually learned the details.

But I'm a user of it - it works even if I don't understand exactly how and nobody tells me that I learned using the mouse "the wrong way" because of it.

Re:Shit – An implementation of Git using POSIX shell by outworlder on Tuesday February 11, 2020 @08:39PM (#22304932)
Yes, and you don't have to spend one hour learning how to push a button.

A version control system is tackling a non-trivial problem. Go learn it properly, otherwise you'll be one of the 'users' that, at best, will be stumped on trivial issues, losing productivity and running to others for help. At worst, you'll be making bad decisions and dragging down your team.

Would you also say that you don't need to learn anything and can just "guess" while working with a programming language?

Re:Shit – An implementation of Git using POSIX shell by onion2k on Wednesday February 12, 2020 @01:18AM (#22306335)
Go learn it properly, otherwise you'll be one of the 'users' that, at best, will be stumped on trivial issues, losing productivity and running to others for help. At worst, you'll be making bad decisions and dragging down your team.

I have no problem with people on my team asking each other for help, and I definitely don't consider it bad for productivity when they do. If someone on my team suggested people asking them for help was bad I would bring it up in their next one to one because that's a really bad sign something is wrong.

If everyone on my team decided to learn the internals of git so they didn't need to ask one another when a problem arose I would be genuinely concerned about how the team is working.

Re:Shit – An implementation of Git using POSIX shell by ptx on Wednesday February 12, 2020 @03:56AM (#22307126)
I think the point was "trivial issues". What if a Java programmer kept asking their teammates if the statement terminator in Java is colon or semicolon?
Re:Shit – An implementation of Git using POSIX shell by onion2k on Wednesday February 12, 2020 @05:22AM (#22307594)
Users can resolve trivial issues without knowing the internals though, so that wouldn't make sense.
Re:Shit – An implementation of Git using POSIX shell by ddevault on Tuesday February 11, 2020 @08:14PM (#22304782)
A typical mouse has 2-3 buttons, a wheel, and an X/Y axis.

Git is 100x more complex, if not more.

Give me a break. I'm sick of people glamorizing the idea that you should have your hand held through each step of every tool you use and never expend any effort on becoming an expert in the tools of your trade. Git is an engineering tool, designed by and for professionals. Imagine this kind of obscene complatency in other fields.

Re:Shit – An implementation of Git using POSIX shell by viraptor on Tuesday February 11, 2020 @09:08PM (#22305106)
I meant the tool-vs-internals idea, not the specific example here. If you want something comparable in complexity: we learn programming from `print "hello world"`, not from memory models and assembly. Some people even just start with `=sum(...)` in excel. Every programmer pretty much stops at the level that's useful and productive for them.

There's often sentiment that people should know more, but I don't think I've ever seen anyone saying starting programming from high level is "the wrong way".

Example from out of it: doctors learn both how to use USG and how it works. But in every case, I've seen it in that order: practice, then internals.

Re:Shit – An implementation of Git using POSIX shell by ddevault on Tuesday February 11, 2020 @09:09PM (#22305111)
>we learn programming from `print "hello world"`, not from memory models and assembly

You're talking to the wrong crowd with me, you know. I disagree with this approach, too. Maybe we start with "hello world" to get a taste, but the first thing we should do is start breaking it down.

Re:Shit – An implementation of Git using POSIX shell by viraptor on Tuesday February 11, 2020 @10:04PM (#22305346)
Thanks. I do understand where you're coming from - your original claim makes sense in that context :-)
Re:Shit – An implementation of Git using POSIX shell by onion2k on Wednesday February 12, 2020 @01:29AM (#22306409)
You understand git. If someone said you need to know how sed works, or grep, or babel, or clang, or bash, or perl, or literally any other tool that you use regularly that you don't know the internals of then you'd quite reaaonably say they were wrong because you're an expert what matters to you and you can do your job without knowing how something else works. Perhaps you should try to respect that other people choose to become experts in things that aren't git.
Re:Shit – An implementation of Git using POSIX shell by frant-hartm on Wednesday February 12, 2020 @05:09AM (#22307534)
If you use any of the tools listed, or any other tool, several times a day then it is reasonable to know the internals at least a bit. If you use grep (or git - the same applies) once a month then it's fine to just memorize some commands.
Re:Shit – An implementation of Git using POSIX shell by na85 on Wednesday February 12, 2020 @12:14AM (#22306012)
I don't think it's asking to have one's hand held to complain about git's poor interface. There's no reason other than lazy design to have a tool where to show all remotes it's

$ git remote -v

But to show all branches it's

$ git branch -a

It's like it's been purposefully designed to be obtuse.

Re:Shit – An implementation of Git using POSIX shell by edflsafoiewq on Wednesday February 12, 2020 @01:22AM (#22306371)
It seems like you've made this example obtuse.

`git remote` and `git branch` list the remotes and branches respectively.

Adding -v makes both of these verbose. It will additionally show what each branch/remote is "pointing at".

Adding -a to `git branch` shows remote tracking branches in additional to local branches. This not normally interesting so the default is to list only local branches.

Re:Shit – An implementation of Git using POSIX shell by reagent_finder on Wednesday February 12, 2020 @02:15AM (#22306627)
...yes, remote tracking branches are interesting as well, I don't know a situation where they wouldn't be.

There's plenty of weirdness in Git, but honestly my main complaint is that the interface is awful and the documentation makes Dostoyevski look modern and sleek.

Re:Shit – An implementation of Git using POSIX shell by majewsky on Wednesday February 12, 2020 @07:16AM (#22308183)
You clearly have not ever worked on repos where nobody ever cleans up after themselves as far as feature branches go. I'm working with repos with remote branches numbering in the hundreds. `git branch -a` is pretty useless at this point unless paired with grep.
Re:Shit – An implementation of Git using POSIX shell by rovr138 on Wednesday February 12, 2020 @10:35AM (#22309618)
this is what I have my alias set to - `git branch -a --sort=-committerdate`
Re:Shit – An implementation of Git using POSIX shell by oblio on Wednesday February 12, 2020 @07:22AM (#22308213)
That's just by accident. There's plenty of obtuse git commands , strange command names, non-standardized parameters, etc.
Re:Shit – An implementation of Git using POSIX shell by aspaceman on Wednesday February 12, 2020 @12:27AM (#22306059)
We're all talking about learning the internals of git and how it works, not it's poorly formed command lines. Pointing out how shitty the interface can be doesn't mean you shouldn't learn how your tools work.
Re:Shit – An implementation of Git using POSIX shell by reagent_finder on Wednesday February 12, 2020 @02:16AM (#22306632)
You say potato, I say potato. If the interface is clunky, you will learn by heart some switches and pass them on as cargo cult.
Re:Shit – An implementation of Git using POSIX shell by na85 on Thursday February 13, 2020 @06:42AM (#22316947)
>We're all talking about learning the internals of git and how it works, not it's poorly formed command lines.

But the argument is being put forward that to understand the command lines you have to understand the internals.

Re:Shit – An implementation of Git using POSIX shell by DagAgren on Wednesday February 12, 2020 @04:30AM (#22307327)
Every other field makes damn sure that their tools are usable, comfortable and as safe as they can be. While programmers act like it's your fault if you hurt yourself while using a chainsaw-hammer.
Re:Shit – An implementation of Git using POSIX shell by danShumway on Wednesday February 12, 2020 @09:30AM (#22309060)
I've watched children use a mouse for the first time, and there is definitely an internal model you needed to learn. No, you don't need to learn exactly how optics work, in the same way that you don't need to learn exactly how Git is reading from files, or how its hashing algorithm is implemented.

But you do need to understand that the mousepad doesn't correspond to points on the screen, and you have to learn to treat it more like a treadmill than anything else. Going back in time and thinking about it from a rollerball perspective can help with that -- new users have a tendency to use something like 90% more space because they don't grok that for long movements they have to pick up the mouse.

People are bringing up the mouse as simple because they're used to using mice. But hand anyone a mouse for the first time and you'll find out that they aren't simple. They're just doing comparatively less than Git, so the problem space is slightly easier to tackle. And that's even ignoring the hand-eye coordination problem we take for granted, and that can take weeks for someone new to computers to get over.

Talking about internal mechanics is broadly useful when teaching computer literacy -- everything from mice, to copy/cut-paste, to shift-selection of files, to the file browser itself benefits from trying to build a systemic, mental model of some kind of behind-the-scenes abstraction.

Re:Shit – An implementation of Git using POSIX shell by seba_dos1 on Wednesday February 12, 2020 @07:45AM (#22308355)
git is a data structure manipulation tool, mouse is a cursor manipulation tool. A much better analogy would be trying to use a mouse without having a good idea of what the cursor is for.

The only difference is that grasping the cursor will probably take you minutes because it's a simple concept, and grasping the data structure takes a bit more effort because it's just a more complicated topic.

You don't need to know the implementation details of git, but you need to know the data structure it operates on, cause otherwise you're just walking in the dark.

Re:Shit – An implementation of Git using POSIX shell by 2zcon on Wednesday February 12, 2020 @06:12AM (#22307851)
And the other IO device? People absolutely will tell you you're typing the wrong way.
Re:Shit – An implementation of Git using POSIX shell by RJIb8RBYxzAMX9u on Wednesday February 12, 2020 @12:19AM (#22306034)
I'm not certain that git will be the dominant VCS forever, as I'd used CVS, Perforce, Subversion, Mercurial, in various degrees when they were dominant (or at least relevant).

Who knows, maybe Linus will have another epiphany, while Microsoft somehow mismanages GitHub and squanders all the goodwill away. Then, a group of upstarts...

That said, wanting to learn git's internals for the sake of knowledge is fine as motivation.

Re:Shit – An implementation of Git using POSIX shell by 101404 on Wednesday February 12, 2020 @03:56AM (#22307127)
Then there's Gitlab and a few others.
Re:Shit – An implementation of Git using POSIX shell by jefurii on Wednesday February 12, 2020 @11:53AM (#22310403)
Also sourcehut / sr.ht.
Re:Shit – An implementation of Git using POSIX shell by Vinnl on Wednesday February 12, 2020 @05:06AM (#22307525)
Even if it stays at widely used as it is now for just two more years it'd already be worth the hour of effort.
Re:Shit – An implementation of Git using POSIX shell by im3w1l on Tuesday February 11, 2020 @07:53PM (#22304676)
It's not a given you will use it for the rest of your career. As two examples, neither Google nor Facebook use git.
Re:Shit – An implementation of Git using POSIX shell by cweagans on Wednesday February 12, 2020 @12:45AM (#22306166)
shrug I'm probably never going to work at either of those places. For pretty much everywhere else, Git works just fine.

Maybe if I play my cards right, I'll use git for the rest of my career. If not, maybe there will be something new eventually, but I imagine that the concepts learned in mastering Git would still be useful.

Re:Shit – An implementation of Git using POSIX shell by jschwartzi on Wednesday February 12, 2020 @10:29AM (#22309555)
You should give Mercurial a try. When you enable the changeset editing extensions it does everything Git does and is much easier to use and understand. I’ve trained people on both systems and Mercurial is much less creaky. The only reason everyone uses Git is for historical reasons because most of the modules In referring to weren’t added to Mercurial until like 09 when Git started seeing widespread use.
Re:Shit – An implementation of Git using POSIX shell by cweagans on Wednesday February 12, 2020 @01:41PM (#22311439)
I used mercurial quite a bit back in 2010. It's nice, but I don't see the value in sinking a bunch of time into it these days.

Every one of the projects that I interact with regularly are in a Git repo on some kind of Git hosting service and the projects are run by people who understand/use Git regularly. For those projects, switching to Mercurial is a net loss, even just considering the time it takes to migrate the codebase + related processes (think CI, issue queue integration, even the repo hosting itself).

Sure, I could use hg-git, but that doesn't gain me much either: now I'm the guy with the weird setup. If something goes wrong with my setup, it's too weird for other people to help with. If something goes wrong with somebody else's setup, I'm not that helpful because I have a weird setup.

Re:Shit – An implementation of Git using POSIX shell by democracy on Wednesday February 12, 2020 @01:07AM (#22306280)
many places were fine with cvs and svn as well
Re:Shit – An implementation of Git using POSIX shell by cweagans on Wednesday February 12, 2020 @09:28PM (#22314824)
Was anyone _really_ fine with cvs?
Re:Shit – An implementation of Git using POSIX shell by buck4roo on Wednesday February 12, 2020 @02:05AM (#22306568)
I'd add that folks should not be forcing the use of git, even within an organization that uses it.

Mercurial works great, has a sane CLI and can both manipulate and interoperate with git repos.

Many of the tools mentioned, at their core, are manipulating the same DAG data structures.

Re:Shit – An implementation of Git using POSIX shell by jschwartzi on Wednesday February 12, 2020 @10:23AM (#22309495)
I found Mercurial to be just as capable and much easier to learn. I’m really only considering moving my team to Git as a least-common-denominator move since nobody really makes tools for Mercurial outside of Facebook. Otherwise it’s harder to learn Git and definitely it’s harder to train interns and juniors to use it.
Re:Shit – An implementation of Git using POSIX shell by BossingAround on Wednesday February 12, 2020 @08:05AM (#22308444)
> neither Google nor Facebook use git

What do Google and FB use as their VCS? Also, any source? I don't mean this to be an attack, I am just genuinely amazed by the statement.

Re:Shit – An implementation of Git using POSIX shell by compiler-guy on Wednesday February 12, 2020 @12:52PM (#22310943)
Google uses a custom implementation of the Perforce interface called Piper. Google has looked at git and mercurial, but have concluded that they can't scale to the level they need it to. Read more about it here:

https://cacm.acm.org/magazines/2016/7/204032-why-google-stor...

Re:Shit – An implementation of Git using POSIX shell by Volt on Wednesday February 12, 2020 @08:19AM (#22308546)
Facebook uses Mercurial.
Re:Shit – An implementation of Git using POSIX shell by masklinn on Wednesday February 12, 2020 @07:30AM (#22308258)
> Why do you think it's the wrong way?

Because the porcelain is a nonsensical pile of crap on it’s own so you really can not make sense of it from the top down, it actively resist that approach.

That’s not an assertion that it’s a good thing mind, just that it’s the only one: learning git from the bottom up is much easier than top-down, and people who dislike that approach are simply hosed.

Re:Shit – An implementation of Git using POSIX shell by zbobet2012 on Tuesday February 11, 2020 @07:34PM (#22304557)
I view not learning the basic concepts of how git works inside like trying to learn SQL without know what a table is.

You could, but its easier if understand that basic abstractions which are its fundamental building blocks.

Re:Shit – An implementation of Git using POSIX shell by hombre_fatal on Tuesday February 11, 2020 @07:41PM (#22304598)
I think it's more like learning enough SQL to build an application without learning about indexes and transactions: you can be sufficiently productive until you encounter corner cases or things go wrong.
Re:Shit – An implementation of Git using POSIX shell by masklinn on Wednesday February 12, 2020 @07:33AM (#22308289)
> I view not learning the basic concepts of how git works inside like trying to learn SQL without know what a table is.

That’s complete nonsense. A table is not a low level implementation detail of sql it’s a core feature.

And I don’t have to known how tables are represented on disk or what they store exactly to acquire a good intuition of how things work.

SQL is in and of itself an abstraction decoupled from the underlying concerns of implementation and execution. Something git’s porcelain definitely is not.

Re:Shit – An implementation of Git using POSIX shell by bfung on Tuesday February 11, 2020 @09:54PM (#22305305)
Theoretically, a person could learn SQL by knowing relational algebra and still not know what a table is. Just sayin’.
Re:Shit – An implementation of Git using POSIX shell by aasasd on Tuesday February 11, 2020 @11:13PM (#22305699)
Git internals are fine. Now, if the utils gave access to human-oriented operations with those internals without the user googling every time they need something not-yet-memorized, that would be splendid. As it is, the utils are already pretty shitty without a reimplementation.
Re:Shit – An implementation of Git using POSIX shell by Hello71 on Tuesday February 11, 2020 @11:51PM (#22305899)
eh, common.sh is a lot more complicated than it could be. example:

    write_hex() {
     hex="$1"
     echo "$hex" | sed -e 's/../&\n/' | while read -r hexbyte; do
      printf "\\x$hexbyte"
     done
    }
you can imagine other shenanigans with xargs or something, but I think this strikes the best balance between performance and readability (as far as shell script goes).

read_int16 and read_int32 don't work on big-endian systems, or if int is 16 bits instead of 32. the latter issue can be easily fixed by explicitly specifying -td2/-td4, but the former issue is not so easy. I think it requires either figuring out the endianness beforehand, or better, something like this:

    od -An -tx1 -j"$offs" -N4 "$path" | while read a b c d; do
     echo $(((0x$a << 24) | (0x$b << 16) | (0x$c << 8) | 0x$d))
    done
oddly, this is used in ls-files already. and yes, I checked: 0x$a is POSIX, and the arithmetic evaluation size must be at least a signed long, which is at least 32 bits.

'for x in $y; do printf "$a%s$b" "$x"; done' is equivalent to 'printf "$a%s$b" $y' (assuming neither a nor b contain format specifiers). similarly, 'for i in {1..100}; do printf "$a"; done' is equivalent to 'printf "$a%s.0" {1..100}'. unfortunately, brace expansion is not POSIX, but these are both significantly more efficient (both in code size and execution time) than the loop methods.

sha1sum is not POSIX. I think shell arithmetic provides you enough tools to implement https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode directly, although it may be slightly slower than a C implementation. awk is probably faster than shell.

Re:Shit – An implementation of Git using POSIX shell by acqq on Wednesday February 12, 2020 @05:09AM (#22307535)
Such a long text... to end with arguing non-POSIX solution. But the initial goal of the project was having a POSIX code, and it can indeed be a valid goal. So the whole post is "a lot more complicated than it could be." Tl dr: you wouldn't make POSIX code.
Re:Shit – An implementation of Git using POSIX shell by Hello71 on Wednesday February 12, 2020 @12:50PM (#22310925)
what the fuck? I specified POSIX alternatives to non-POSIX uses in the code. only one feature, brace expansion, is not POSIX, so I specifically did not recommend its use.
Re:Shit – An implementation of Git using POSIX shell by acqq on Wednesday February 12, 2020 @04:51PM (#22313189)
Th specific part that I understood as your argument for non-POSIX solutions:

"'for x in $y; do printf "$a%s$b" "$x"; done' is equivalent to 'printf "$a%s$b" $y' (assuming neither a nor b contain format specifiers). similarly, 'for i in {1..100}; do printf "$a"; done' is equivalent to 'printf "$a%s.0" {1..100}'. unfortunately, brace expansion is not POSIX, but these are both significantly more efficient (both in code size and execution time) than the loop methods."

I didn't understand why you write that part at all, considering the goals of the program we discuss (which is to demonstrate some git primitives in POSIX compliant shell code).

Re:Shit – An implementation of Git using POSIX shell by Hello71 on Thursday February 13, 2020 @12:00PM (#22319271)
'for x in $y; do printf "$a%s$b" "$x"; done' is used in the code already. I am proposing that it be changed to 'printf "$a%s$b" $y', which is also POSIX compliant, shorter (even including a comment), and faster. I included the part about brace expansion as a side note, not proposing that it be used.
Re:Shit – An implementation of Git using POSIX shell by acqq on Thursday February 13, 2020 @03:46PM (#22321266)
> 'printf "$a%s$b" $y', which is also POSIX compliant, shorter

Yes, indeed, thanks for pointing that, it's documented:

"The format operand shall be reused as often as necessary to satisfy the argument operands."

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/p...

Re:Shit – An implementation of Git using POSIX shell by acqq on Wednesday February 12, 2020 @02:34PM (#22311967)
I’m sorry if I misunderstood you. I’m indeed interested in what from all you wrote is then what you would suggest to be changed, as I also looked at his code and also read here that it was done in short time so I also believer there are possibilities for improvement. Specifically, reimplementing sha calculation itself should be a non goal, in my opinion. Just that the .sh code itself works on all POSIX shells, not that the whole system has to be POSIX only: calculating sha in shell is surely not the point of demonstrating how git works.
Re:Shit – An implementation of Git using POSIX shell by aequitas on Wednesday February 12, 2020 @04:57AM (#22307477)
Would you say if the data format was say JSON, YAML or TOML or any more human and bash friendly format it would have been easy to implement with your current experience?

Not to vouch for having Git store things in human format. But I often think about how inefficient JSON API's and YAML storage formats are (in parse time) just to be a benefit of a user debugging it or discovering the API through a browser. But since most people use a JSON prettifier plugin or a tool like Postman anyways, what is the benefit of the line format being character strings? Wouldn't a binary package not be just as easy translatable into human readable JSON formatted output as a compacted JSON string is?

Re:Shit – An implementation of Git using POSIX shell by Sean1708 on Wednesday February 12, 2020 @05:17AM (#22307579)
> what is the benefit of the line format being character strings? Wouldn't a binary package not be just as easy translatable into human readable JSON formatted output as a compacted JSON string is?

One benefit is that I can look at an arbitrary file/response and be able to tell with a fairly high certainty whether it's JSON, YAML, or TOML, but there's no way that I tell whether it's messagepack, bson, or protobufs.

Re:Shit – An implementation of Git using POSIX shell by aequitas on Wednesday February 12, 2020 @05:34AM (#22307659)
Most of the time you know the format you expect to decode you don't have to guess it anyway.

But I think you should be able to detect the type of format for binary encodings just as well as there spec is pretty specific. Maybe not at glance as a human, but that is the point I'm making. Should all line formats be made absolute human readable and parsable at glance just to the benefit of debugging at the cost of performance. Where with just a simple lens tool you can look at the data in a completely different (human friendly) view. Tools like this already exist in the form of WireShark, only they mostly operate at a deeper level.

Re:Shit – An implementation of Git using POSIX shell by whalesalad on Wednesday February 12, 2020 @02:18AM (#22306639)
Even with the self deprecating nature of this effort and project: you continue to produce a lot of open source contributions. I see your work and blog all over the place. You’re a machine!

So what’s your secret?

Re:Shit – An implementation of Git using POSIX shell by agumonkey on Tuesday February 11, 2020 @07:40PM (#22304592)
Re:Shit – An implementation of Git using POSIX shell by peterwwillis on Tuesday February 11, 2020 @11:20PM (#22305739)
Still more sane than JavaScript to me. Would use this over a 500MB Node.js implementation.
Re:Shit – An implementation of Git using POSIX shell by efreak on Wednesday February 12, 2020 @12:04AM (#22305956)
Is this a reference to something? I can't imagine it would take 500mb to reimplement git in JavaScript. This one's <75kb and full of explanations: https://github.com/maryrosecook/gitlet
Re:Shit – An implementation of Git using POSIX shell by GordonS on Wednesday February 12, 2020 @04:04AM (#22307170)
It's a dig at the typical size of a `node_modules` folder. These often are very large, and often do contain several thousand files, largely due to transitive dependencies.
Re:Shit – An implementation of Git using POSIX shell by thcz on Wednesday February 12, 2020 @01:21AM (#22306364)
For anyone looking to use Git in JS, check out https://github.com/isomorphic-git/isomorphic-git. I've had great success with it and really like it as a library. It's API design is good and it's tree-shakeable so the size of the library is very reasonable, even if taking it as a whole.
Re:Shit – An implementation of Git using POSIX shell by globular-toast on Wednesday February 12, 2020 @08:38AM (#22308684)
Indeed, I've come to the same conclusions myself. I'm the resident git expert at my job but, quite honestly, the only thing that separates me is that I've learnt git's internals. But I learnt it because I'm lazy and it's easier, not because I want to be the best or anything.

So many people say they "know" git, but then I watch them work and it's "git commit -a" all the time and "git clone" when something doesn't look right. It's really amazing how people refuse to learn this essential tool.

Re:Shit – An implementation of Git using POSIX shell by kakakiki on Wednesday February 12, 2020 @12:34AM (#22306097)
Couldn't resist looking at it after your repeated warnings. It seems that shellcheck site has some suggestions to improve the code.
Re:Shit – An implementation of Git using POSIX shell by Iwan-Zotow on Wednesday February 12, 2020 @03:26PM (#22312453)
You know that Linus wrote first version of git in mostly bash, right?
Re:Shit – An implementation of Git using POSIX shell by juped on Tuesday February 11, 2020 @07:47PM (#22304635)
Why even have the index? Just skip that step.
Re:Shit – An implementation of Git using POSIX shell by ddevault on Tuesday February 11, 2020 @07:49PM (#22304642)
I wanted to have the staging area, and I had decided upfront that I wouldn't make the repository state inconsistent between shit and git. So the index needed to be done.

Also, you need to generate a tree out of something. Could just hash the entire worktree every time, but that would be pretty lame.

Re:Shit – An implementation of Git using POSIX shell by deathanatos on Tuesday February 11, 2020 @09:26PM (#22305181)
What I never fully understood is why the staging area isn't simply a commit that gets amended repeatedly as files are staged into it. Maybe just a tree pointer, since the rest of the commit data isn't available until commit, but you could fill in some placeholders. ("(staging)" for the message, current times for the timestamps, etc.)

(Note that index doubles for other functions like merging/conflict resolution, but I never thought that was a good thing, and could be separated out.)

Re:Shit – An implementation of Git using POSIX shell by smichel17 on Tuesday February 11, 2020 @10:54PM (#22305579)
I've wanted this for a long time, and also a frequently-amended working-tree-as-a-commit.

Why? I prefer a each branch to have its own staging area and working tree, which maps better to my mental model of "branch as an under-development feature".

Currently my workflow to achieve this involves a lot of stashing.

Re:Shit – An implementation of Git using POSIX shell by _ikke_ on Wednesday February 12, 2020 @12:54AM (#22306209)
Do you know about git worktree? Because that sounds exactly what you want. Each worktree has its own index (staging area) and working tree.
Re:Shit – An implementation of Git using POSIX shell by rswail on Wednesday February 12, 2020 @12:01AM (#22305944)
What's the difference between a stash and a "working tree as a commit"?
Re:Shit – An implementation of Git using POSIX shell by _ikke_ on Wednesday February 12, 2020 @12:51AM (#22306194)
The 'staging' area is implemented through the index. And the index is used for more things then just deciding what gets in the next commit. A lot of gits speed comes from caching Stat data of files so that it does not have to hash the complete working tree for each operation. That's not something you can just ignore.

Someone proposed splitting this up the other day, but even that would come at the cost of performance and an increase of complexity.

Re:Shit – An implementation of Git using POSIX shell by doubleunplussed on Wednesday February 12, 2020 @10:50AM (#22309771)
Wow, I just totally assumed the index was a tree object. It seems much less elegant that it isn't.

Maybe it isn't because it would necessitate creating a lot of blob objects as you staged and unstaged changes, which might not get garbage collected for some time. I can't see any other reason.

Re:Shit – An implementation of Git using POSIX shell by AsyncAwait on Wednesday February 12, 2020 @08:37AM (#22308680)
For anyone wanting to understand Git from inside out at a fundamental level, I can't recommend the 'Building Git' book enough.

The code is Ruby, but there's enough explanation for each snippet to be able to follow along in whatever language one prefers. I had no problems with translating to Go, for example.

1 - https://shop.jcoglan.com/building-git

Re:Shit – An implementation of Git using POSIX shell by cs702 on Tuesday February 11, 2020 @07:45PM (#22304621)
Love the name -- very fitting.

> I said that the internals were so simple that you could implement a workable version... inside of an afternoon. So I wrapped up what I was working on and set out to prove it.

Been there. Done that. With other things, not git.

I suspect many others here have too.

> Five hours later, it had turned into less of a simple explanation of "look how simple these primitives are, we can create them with only a dozen lines of shell scripting!" and more into "oh fuck, I didn't realize that ...". Then it became a personal challenge to try and make it work anyway...

Yep. Been there too. Done that too. Again, with other things, not git.

I suspect many others here have too.