News for hackers. Stuff that matters.
Re:Write yourself a Git (2018) by cabalamat on Thursday March 14, 2019 @07:32AM (#19388261)
I have an admission to make: I don't understand git. By this I mean I have a few simple commands I use (status/add/commit/push/pull) and if I try to do anything more complicated it always ends up with lots of complex error messages that I don't understand and me nuking the repository and starting again.

So I think: there must be a better way.

I have often thought about implementing a VCS. The idea behind one doesn't seem particularly complex to me (certainly it's simpler than programming languages). If I did I would quite probably use WYAG as a starting point. My first step would be to define the user's mental model -- i.e. what concepts they need to understand such that they can predict what the system will do. Then I would build a web-based UI that presents the status of the system to the user in terms of that model.

Re:Write yourself a Git (2018) by AnIdiotOnTheNet on Thursday March 14, 2019 @08:00AM (#19388406)
Yeah, I too don't really understand git. It seems that it was developed without any concern for affording a good mental model of its operation to its users, and thus it is just a complex black box you chant arcane rituals at and hope it doesn't decide to burn your world down. I know I could build a mental model of it if I put enough time into it, but who wants to do that when there's actually useful things to do? So instead when I have to use it to contribute to open source projects I have a sheet of notes with incantations to cover the specific things I've had to do with it in the past.
Re:Write yourself a Git (2018) by totallymike on Thursday March 14, 2019 @09:38AM (#19389080)
This is a valid point. Git is sometimes incomprehensible. The best way to build a mental model for me has been to read about directed acyclic graphs. It’s all just trees, objects, and labels for trees and objects from there.

Also to learn that `git reflog` exists, and gives you pointers to all the old states of your repo, even mid-merge or mid-rebase. If you get stuck with a bad rebase, you’re only a `git reflog; git checkout HEAD@{3}` away from being back where you started.

Tutorials like this one and others mentioned throughout the thread do a good job of breaking down the viscera from there.

Re:Write yourself a Git (2018) by nlawalker on Thursday March 14, 2019 @01:41PM (#19391540)
>> developed without any concern for affording a good mental model of its operation to its users, and thus it is just a complex black box you chant arcane rituals at

That's not git, that's the command line - the interface with no inline visualization, no discoverability and no affordances.

git is not its command line interface. I use the git CLI like I use curl: a powerful tool for occasional surgical or automated operations directly on underlying protocol. Most of the time I prefer something that better fits my workflow: for git, it's Git Extensions; for HTTP, it's Chrome.

Re:Write yourself a Git (2018) by chousuke on Thursday March 14, 2019 @02:14PM (#19391844)
I have the exact opposite problem. I have a mental model of git, but not a very good one for most of its competitors; I don't really get mercurial for example, but git is just:

1) uncommitted stuff in workdir. Potentially can be lost, so commit often.

2) blobs in repo representing snapshots at commit time. Can never be lost.

3) symbolic references to the blobs. Can always recover from reflog.

4) tools to sync the above two things between repositories. (fetch and push)

5) tools to merge, diff and otherwise manipulate the changes between snapshots and files.

I'm confident that git will never lose my data, so long as I commit it. This makes experimentation stress-free.

Technically, you can lose data by explicitly deleting your refs, expiring the reflog, and running gc, but if you go that far you might as well rm -r .git

Re:Write yourself a Git (2018) by krupan on Thursday March 14, 2019 @02:50PM (#19392240)
Mercurial is the same except:

0) you forgot to explain git's index. Mercurial doesn't have the index, it works how you described git.

2) data (blobs, revsets, whatever) in the repo actually can never be lost, there is no automatic gc

3) no need for some different tool/viewer to view commits that don't have refs

Technically there are several ways to remove data from the repo, but it never ever happens automatically behind your back.

Re:Write yourself a Git (2018) by chousuke on Thursday March 14, 2019 @04:37PM (#19393426)
The mental model helps me with git because it maps pretty closely to what data actually exists. The index is just a useful thing to help me put stuff into a repository in a controlled manner. I've never attained a similar transparent understanding of mercurial.

I think I've asked this before, but what exactly are mercurial's branches?

In git, they are a "physical" feature of the repository as it represents a set of lineages, not an actual repository object.

As such, any reference to a commit uniquely identifies a branch, so the concept of a "named line of development" is simply implemented as a reference that gets updated as you make more commits. When you "delete" a branch in git, it goes nowhere. Only its name is removed.

What sort of structure does mercurial use to represent its branches? I know they are not just an emergent thing like in git.

Re:Write yourself a Git (2018) by krupan on Thursday March 14, 2019 @06:38PM (#19394595)
Mercurial uses a DAG just like git. It has facilities for embedding a branch name in each commit, or for not doing that and having anonymous branches. It also has a feature similar to git's "branches"

Two articles that might help if you really want to dig into it:

http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-me...

https://bryan-murdock.blogspot.com/2013/06/git-branches-are-...

Re:Write yourself a Git (2018) by chousuke on Friday March 15, 2019 @02:18AM (#19397025)
Hmm, so the branch names are part of the commit's metadata. I'm not sure I agree with that, but I guess it's a valid choice.

The first article also states that unnamed branches are useful for small, temporary diversions, and notes that git has to name branches, but I think that's somewhat misrepresenting git since you can throw away names as soon as they are no longer useful. To me it seems kind of silly to have unnamed branches, given that names are free and much easier to remember than commit hashes.

Re:Write yourself a Git (2018) by cabalamat on Thursday March 14, 2019 @08:07AM (#19388445)
> It seems that it was developed without any concern for affording a good mental model of its operation to its users

I think Linus' design goal was something that runs as quickly/efficiently as possible on large repositories.

> it is just a complex black box you chant arcane rituals at and hope it doesn't decide to burn your world down

My feeling too!

Re:Write yourself a Git (2018) by influx on Thursday March 14, 2019 @09:56AM (#19389217)
No, his design goal was to create a vcs for the Linux kernel. Frankly most people use git like svn version 2, completely skipping the distributed parts of it.

Git actually doesn’t scale to really huge monorepos.

Re:Write yourself a Git (2018) by Deganta on Thursday March 14, 2019 @11:12AM (#19389920)
That's because most users don't actually need the distributed part of git. For most projects the sanest solution is to have a single master repository that all users pull/push from/to.

IMHO the only real advantages over SVN for most users are the better branch/merge functions.

Re:Write yourself a Git (2018) by jancsika on Thursday March 14, 2019 @03:04PM (#19392411)
In other words-- git is so good at being decentralized you only notice the consequences in the improved branch/merge UX.
Re:Write yourself a Git (2018) by cabalamat on Thursday March 14, 2019 @07:44PM (#19395062)
> his design goal was to create a vcs for the Linux kernel

Which is a largish piece of software.

Re:Write yourself a Git (2018) by hvis on Thursday March 14, 2019 @10:23AM (#19389454)
> black box

Have you tried looking into any other contemporary DVC systems?

I get Git, more or less. Having tried to make sense of Bazaar or Mercurial on several occasions (to understand the internal data model), I eventually gave up.

Re:Write yourself a Git (2018) by pdonis on Thursday March 14, 2019 @10:35AM (#19389567)
Are there other VCSs that you find it easier to understand and build a mental model of?
Re:Write yourself a Git (2018) by AnIdiotOnTheNet on Thursday March 14, 2019 @01:48PM (#19391608)
Personally I just rely on daily backup of my workstation and manually copied and compressed snapshots of the project when I feel significant progress has been made. I tried SVN once, but it wasn't very transparent what it was doing and didn't really enhance my workflow any.
Re:Write yourself a Git (2018) by pdonis on Thursday March 14, 2019 @02:02PM (#19391732)
Is all of your coding projects that you are working on by yourself? Or do you have to share code with other people?
Re:Write yourself a Git (2018) by AnIdiotOnTheNet on Friday March 15, 2019 @09:31AM (#19399509)
All my personal projects are just me. When I contribute to open source projects I use whatever they use, which is usually git. At work, even though I am usually the only programmer on my programming projects, I use TFS because that's the company's process.
Re:Write yourself a Git (2018) by js2 on Thursday March 14, 2019 @09:07AM (#19388838)
Perhaps the Git Parable will help:

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

To provide an alternate viewpoint, I have never had trouble with Git. I’m a bottom-up how-does-this-thing-work sort of person so when I first started using Git, I sought to understand how it worked. That part of Git is pretty easy to understand. Knowing that made its CLI a lot easier to grok. Of course, at the time I was having to use ClearCase at work and Subversion on the side so Git, IMO, was a vast improvement to either of those tools.

Re:Write yourself a Git (2018) by tsukikage on Thursday March 14, 2019 @12:30PM (#19390808)
git is to version control systems as vim is to text editing or dwarf fortress is to god sims.

(dear everyone here and elsewhere recommending git incantations "but of course you have to know what you're doing": if you regularly have to take a backup of your working area before interacting with the vcs, because the interaction may do things you did not intend from which the simplest way back is to reset hard and start over, I humbly suggest that the vcs has failed in its primary purpose)

Re:Write yourself a Git (2018) by chousuke on Thursday March 14, 2019 @02:25PM (#19391936)
I'm not sure if I'm reading your comment right, but if you're going to do something that might result in a mess (such as a merge or a rebase) the sane thing to do is not to have anything uncommitted in your workdir; that way you can always retry, undo and experiment, and the VCS is doing exactly what it's supposed to be doing.

It's something subversion can't do last I checked, so whenever I need to do a complicated operation with SVN, I import the local state into a git repo first :P

Re:Write yourself a Git (2018) by neals on Thursday March 14, 2019 @08:06AM (#19388438)
I think this is a large majority of Git users. The last company I worked at had 30 good developers, 1 of which I think really deeply understood git.

So I guess 97% of users don't really get git.

Re:Write yourself a Git (2018) by cabalamat on Thursday March 14, 2019 @07:55PM (#19395117)
> The last company I worked at had 30 good developers, 1 of which I think really deeply understood git.

I think this is really damning. Developers understand complex languages/compilers like C++, Python, Java, etc, all of which have a good deal more intrinsic complexity than a VCS. So if a VCS isn't understood, it is badly designed.

Re:Write yourself a Git (2018) by frosted-flakes on Friday March 15, 2019 @02:45PM (#19402881)
It's because it's so opaque and inconsistent. If git was a program like Microsoft Word, where every available action is easily discoverable and the current state is obvious, then it wouldn't be so bad. Something like what Nikita Tonsky wrote in an article called "Reinventing Git Interface"[0], which has a lot of good ideas.

[0] http://tonsky.me/blog/reinventing-git-interface/

Re:Write yourself a Git (2018) by elviejo on Thursday March 14, 2019 @09:18AM (#19388920)
I'm in the same boat. I could teach subversion in 1 hour and people would get it. I can't teach git in a whole week. So in the end my students use the same 5 commands.
Re:Write yourself a Git (2018) by cmroanirgo on Thursday March 14, 2019 @07:46AM (#19388329)
I'm like you. I use SourceTree to get a 'visual grasp' on what I find to be the noise of git commands. However, if you're into command line, you can try fossil: it's got lots going for it.

Your idea of a "user's mental model" might land you into trouble though, because all of us come from different backgrounds (subversion, SSafe, git, HG...) and they all maddeningly redefine terms in different ways (eg branch, forks, commits, checkout).

Re:Write yourself a Git (2018) by Nr7 on Thursday March 14, 2019 @08:12AM (#19388480)
Using a git client with a graphical user interface has definitely helped me "grok" git as well. I use Git Extensions myself.
Re:Write yourself a Git (2018) by cabalamat on Thursday March 14, 2019 @08:05AM (#19388434)
> Your idea of a "user's mental model" might land you into trouble though

If I do do this, I will explicitly lay out the user's metal model in the documentation at the start. Then it will be the user's fault if they can't be bothered to read it.

Re:Write yourself a Git (2018) by huffstler on Thursday March 14, 2019 @09:28AM (#19389004)
While gits documentation might not lay out the model at the start, they certainly have documentation showing how everything works, complete with diagrams and such. As such...

> Then it will be the user's fault if they can't be bothered to read it.

can be applied to you about git technically. I think that's just me being a "little" pedantic though.

It sounds like the issue you actually have is that the documentation isn't easily readable in one or two sittings, and you don't have the time (or can't be bothered) to go through it and learn it. Which I totally understand, everyone has different things they need to spend time on, most of the time learning Git isn't one of them.

Re:Write yourself a Git (2018) by cabalamat on Thursday March 14, 2019 @07:48PM (#19395078)
> can be applied to you about git technically.

I have read large parts of the git docs. I don't like them. This is not just the text: the low contract colours and hard-to-read fonts are also factors.

> It sounds like the issue you actually have is that the documentation isn't easily readable in one or two sittings, and you don't have the time (or can't be bothered) to go through it and learn it.

So how long should it take to learn a VCS? And how long does git take to learn?

Re:Write yourself a Git (2018) by derekp7 on Thursday March 14, 2019 @08:10AM (#19388469)
Look for a video on YouTube called Git Happens. I've found it fairly effective with my coworkers. It doesn't go over the command syntax, but instead dives into a logical overview of the underlying data structures.
Re:Write yourself a Git (2018) by rezeroed on Thursday March 14, 2019 @08:25AM (#19388560)
I'm not much better. I knew SVN inside out. I've read up on git internals, poked around with them, but eventually forget it all because 99% of the time I only use the same five commands. It's a real iceberg, Pareto principle piece of software for me.
Re:Write yourself a Git (2018) by rsp1984 on Thursday March 14, 2019 @09:01AM (#19388795)
Just curious: Have you tried any of the git GUIs out there? There are many good ones: Fork, Git Tower, GitX-dev.

I guess I would be lost as well just using the command line.

Re:Write yourself a Git (2018) by cabalamat on Thursday March 14, 2019 @08:02PM (#19395150)
> Have you tried any of the git GUIs out there?

I regularly use Giggle.

> Fork, Git Tower, GitX-dev

None of these work on Linux. GitX-dev also has a website I have difficulty reading.