News for hackers. Stuff that matters.
Re:Things I wish everyone knew about Git (Part I) by skrebbel on Wednesday June 29, 2022 @03:00PM (#31924334)
Fwiw a branch isn't a named sequence of commits, it's just a label that points to a single commit. It's exactly the same as a tag except that git moves it when you make a new commit.

Mercurial calls these bookmarks which IMO is a much better name because it works exactly like real bookmarks (in books, not browsers). A git branch feels a little bit like a branch of a tree because each commit points to their parent. Therefore, you don't need to track the entire sequence of commits in the branch but just the commit at the tip. I think if they'd had named only this concept better, Git would've been way easier to grok.

I wouldn't usually nitpick like this but given that the entire point of this article is it matters to get the basic concepts right, I figured the author might want to get this basic concept right.

Re:Things I wish everyone knew about Git (Part I) by HWR_14 on Wednesday June 29, 2022 @05:14PM (#31925796)
Am I the only one sad that Git beat out Mercurial as the industry standard?

And am I also the only one who still knows how to do things in Mercurial but not how to take the corresponding action in Git? I mean, they're things I haven't had a reason to do in years, but it has some psychological cost to feel like I'm using a system I'm worse at.

Re:Things I wish everyone knew about Git (Part I) by brianwawok on Wednesday June 29, 2022 @06:57PM (#31926736)
I was on the team of a large org doing a POC between the two. Merc did some stuff better, git did more. I am glad git won out overall. I think the only feature Merc had that I cared about was tracking folders as objects.
Re:Things I wish everyone knew about Git (Part I) by HWR_14 on Wednesday June 29, 2022 @07:07PM (#31926850)
Mind if I ask what Git did better? The main selling point for the difference between them was the Linus, Linux and then the whole community chose Git.

The only big difference I recall Git winning on was in third party tooling and Git supporting more than two parents merging.

Re:Things I wish everyone knew about Git (Part I) by brianwawok on Thursday June 30, 2022 @09:38AM (#31932188)
This was a lot of years.. but things like:

1) We used some super crappy Clearcase version control system. It was easier to layer Git on top, letting us have a VC on top of a VC. I can't remember if it was impossible, or just easier to do in Git.

2) Conflicts did better. We made kind of torture test of merges and put both systems through. Git was able to resolve more out of the box.

3) Speed of operations, I think Git was a bit faster out of the box.

None of this was about Github, as it was comparing self hosted HG vs self hoted GIT.

Re:Things I wish everyone knew about Git (Part I) by toyg on Wednesday June 29, 2022 @07:41PM (#31927106)
Git wasn't really winning until GitHub emerged. The game was still open at that point. Once GH had resoundingly beat the competition for "social coding" (like bitbucket and sourceforge), though, it was all over.
Re:Things I wish everyone knew about Git (Part I) by fero14041 on Friday July 01, 2022 @03:42AM (#31943549)
Mike Bayer, creator of SQLAlchemy ORM in Python, wrote about migrating its repository from Mercurial to Git, in 2013: https://www.sqlalchemy.org/blog/2013/05/25/sqlalchemy-migrat... He had some IMHO strong points in favor of Git itself VS Hg, besides GitHub and its huge userbase, which personally convinced me to switch.
Re:Things I wish everyone knew about Git (Part I) by bsder on Thursday June 30, 2022 @04:15AM (#31929922)
> Am I the only one sad that Git beat out Mercurial as the industry standard?

Quibble: Git didn't win. Github won. Git was simply the parasite on the Github host.

However, I feel just like you. Mercurial is just so ridiculously easier to explain to people.

I really don't understand what it is about Git that seems to prevent anybody from coming up with a sane UX for it.

Re:Things I wish everyone knew about Git (Part I) by shikoba on Thursday June 30, 2022 @05:29AM (#31930315)
> I really don't understand what it is about Git that seems to prevent anybody from coming up with a sane UX for it.

That's the problem. Git has a sane UX. The only issue is that a lot of people who doesn't understand it, write silly tutorials where they spread their misconception about it. The real issue is the poor quality of tutorials over the internet that mislead a lot of people.

Re:Things I wish everyone knew about Git (Part I) by woojoo666 on Thursday June 30, 2022 @07:37AM (#31931141)
I don't think the UX is that intuitive. If you want to tweak a commit that's not the branch head, you have to rebase the parent of that commit. From a technical standpoint this sort of makes sense, but for a casual user this is not intuitive at all
Re:Things I wish everyone knew about Git (Part I) by shikoba on Thursday June 30, 2022 @10:23AM (#31932696)
> If you want to tweak a commit

Here we are. You can't tweak a commit in git. You want to recreate a new one. That's why UX is awful, because there is a permanent confusion about what git does.

Re:Things I wish everyone knew about Git (Part I) by woojoo666 on Friday July 01, 2022 @02:28AM (#31943090)
I know that rebasing creates a new commit (and all commits thereafter). As I said, from a technical standpoint I get it. But I don't see why there can't be a simple command or button that lets to modify a single commit, and performs the rebase behind the scenes. I commonly need it in my private repos and branches. But right now the rebase operation we're stuck with is very low-level and unintuitive.
Re:Things I wish everyone knew about Git (Part I) by mathstuf on Thursday June 30, 2022 @08:43AM (#31931664)
You rebase onto the parent of that commit. The parent doesn't change. Or am I misunderstanding what you're describing here?
Re:Things I wish everyone knew about Git (Part I) by woojoo666 on Friday July 01, 2022 @02:25AM (#31943073)
But the average casual user just wants to modify the commit. There could easily be a higher level command for this, which internally finds the parent and performs the rebase, but instead Git (and even most GUI tools on top) forces you to go the manual route of selecting the parent and initiating a rebase. It's counterintuitive
Re:Things I wish everyone knew about Git (Part I) by mathstuf on Friday July 01, 2022 @06:24AM (#31944507)
There is the ~ or ^ suffix to select a parentage. Also, vin-fugitive selects the parent automatically when you say "rebase starting here" on a commit under the cursor. Not sure what it does for merge commits; there's so great default there.
Re:Things I wish everyone knew about Git (Part I) by woojoo666 on Friday July 01, 2022 @07:17AM (#31944819)
You still have to go through the "pick"/"reword" flow though. Most of the time people just want to modify a single commit. So why not just have a command for it, instead of needlessly exposing the low-level rebase process to the users
Re:Things I wish everyone knew about Git (Part I) by shikoba on Friday July 01, 2022 @07:59AM (#31945185)
git commit --amend

Or git rebase

It's two simple command

Re:Things I wish everyone knew about Git (Part I) by woojoo666 on Friday July 01, 2022 @06:39PM (#31953924)
Git commit amend only works if you want to modify thr latest commit. Rebase is unnecessarily complicated if you just want to modify a single commit. It should be something more like `git edit [commit sha]`
Re:Things I wish everyone knew about Git (Part I) by mathstuf on Saturday July 02, 2022 @07:41AM (#31958198)
That gets complicated. What if there's a merge commit between here and there? How about a conflict? You cannot hide the underlying mechanism of reapplying a set of changes.

On that note, I have written something like this, but it is not something I think belongs in the standard toolbox. It is a tool that applies "formatting" fixes to a topic, preserving history topology. However, it requires some automated tool to be able to perform the edit so that any conflicts can be resolved by running the tool to perform the edit (typically clang-format or autopep8, but sed or something like that is also a candidate). I don't know that requiring your edit to be expressed in terms of sed is suitable for such a "simple" tool to replace rebase.

Re:Things I wish everyone knew about Git (Part I) by woojoo666 on Sunday July 03, 2022 @06:26PM (#31971545)
It would still use rebase in the background. If there's a conflict that happens when reapplying changes, then an error pops up, and the user can look into it and will start to understand the process. But in my experience of just doing quick patches on my private repos (where I do multiple small commits a day so patching an earlier commit is relatively common), a conflict rarely ever happens. I think I've run into it once in my many years of dev.

So for the majority of users, they wouldn't have to even know about rebase until they have quite a bit of experience with git (and programming in general). It's a better learning curve, especially considering Git is now being taught to beginner programmers.

A `git edit` command is not as powerful as `git rebase`, but this is just how UX works. You expose a smaller simpler set of features at the front, and then (if you aren't Apple) allow the users to do more advanced low-level operations if they need to.

Re:Things I wish everyone knew about Git (Part I) by mathstuf on Monday July 04, 2022 @07:43AM (#31975974)
I, on the other hand, do something similar, but run into conflicts all the time. Usually when reordering commits or fixing up missed hunks that belong in some older patch. I do conflict resolution dozens of times a week.

I guess we just disagree on how shallow or deep any problems `git edit` tries to hide are in practice and therefore how much convenience it actually saves.

Re:Things I wish everyone knew about Git (Part I) by bsder on Thursday June 30, 2022 @08:53PM (#31940748)
So why is it that every other source control system seems to have such nice tutorials?

We can either posit that the people who made and use Git are substandard, or we can posit that there is something fundamental about Git that makes writing such tutorials difficult.

Re:Things I wish everyone knew about Git (Part I) by cryptonector on Wednesday June 29, 2022 @06:00PM (#31926216)
I'm not sad.

Mercurial is opinionated. It's had to adopt the Git way slowly, grudgingly.

Re:Things I wish everyone knew about Git (Part I) by mathstuf on Thursday June 30, 2022 @08:45AM (#31931693)
I like the stage way more than not having it. I think Mercurial has it now as some extension, but my fingers know Git and git-hg is the only way I interact with the tool these days.

Explicit rename tracking is a mistake though. I think Linus got that one right.

Re:Things I wish everyone knew about Git (Part I) by jsmith45 on Wednesday June 29, 2022 @03:52PM (#31924938)
This is exactly the point the author plans to address under "Branches are fictitious", in the outline at the top.
Re:Things I wish everyone knew about Git (Part I) by skrebbel on Wednesday June 29, 2022 @05:02PM (#31925670)
Sure but then why do they describe the term wrong in the first paragraph? That's just adding to the confusion they intend to fight. I'm not sure the author is reading this, but think it's worth rewording.
Re:Things I wish everyone knew about Git (Part I) by mjd on Wednesday June 29, 2022 @06:07PM (#31926284)
I'm reading it and I think I got it right. The Git community, the Git documentation, and the Git tools all refer to "branches", and I think what they mean when they talk about "branches" is much closer to what I described than to what you did.

For example, consider this very ordinary-sounding phrase that I just picked out of the git-rebase man page:

> If the upstream branch already contains a change you have made …

I don't think your account can explain what is meant by this.

In any case, I didn't make the choice casually, thoughtlessly, or from ignorance.

Re:Things I wish everyone knew about Git (Part I) by skrebbel on Thursday June 30, 2022 @01:18AM (#31928930)
> In any case, I didn't make the choice casually, thoughtlessly, or from ignorance.

Obviously, and if you got the idea that I thought you did then I apologize for that.

Anyway, the git docs aren't exactly known for getting the nuances of its own concepts right, which adds to the general confusion.

That said, I think I see your point now: it's the same as how a reference to a linked list is actually just the head of the linked list, but you still call it a list and not a head.

I have to admit that maybe I didn't see the forest for the trees.

Re:Things I wish everyone knew about Git (Part I) by pierrebai on Wednesday June 29, 2022 @07:34PM (#31927067)
The problem is that your rebuttal isn't one: you are not addressing any of the points made. And those points are important precisely because branches are not a range of commits which is why they are cumbersome to work with.
Re:Things I wish everyone knew about Git (Part I) by layer8 on Wednesday June 29, 2022 @06:26PM (#31926446)
But what’s the precise rule defining what constitutes the commits of a branch, after you reach a merge point? Does the branch end there? If not, which parent of the merge does it go? It’s not clear a priori.
Re:Things I wish everyone knew about Git (Part I) by mjd on Wednesday June 29, 2022 @07:04PM (#31926817)
I don't think there is a precise rule. because the exact meaning depends on the context. In part 3 of the series, in the section about "branches are fictitious", that's what I will say.

The talk has an abbreviated version: https://perl.plover.com/classes/git-tips/samples/slide018.ht... It's an illustration of just one example of this: If we rebase "branch X" onto commit B, we rebase only the three green commits. But if we rebase it onto C, we consider X to contain the two dark blue commits also.

Are the dark blue commits part of branch X? It depends on what you're trying to communicate.

Re:Things I wish everyone knew about Git (Part I) by layer8 on Wednesday June 29, 2022 @09:54PM (#31927927)
Right, and that’s what makes “branch” a vague notion in git. It’s not clear what exactly is meant with “branch x” when it’s not just about the labeled tip, and often enough no further clarification is given.
Re:Things I wish everyone knew about Git (Part I) by shkkmo on Thursday June 30, 2022 @12:30PM (#31934931)
Every commit contains an ordered list of it's parent commits. You could think of the 'main' history as being the chain of commits that are always the first ancestor to each other and this can be a use thing to display when generating a commit history.

However, the history of a commit is always the entire tree of ancestors. This entire tree is the precise definition of what constitutes all the commits of a branch.

Thus while I agree that it is not wrong to view a branch as a bookmark, I also think that attempts to nitpick the man page's use of the term fall flat here. "Commit contained in a branch" just means: "commit contained in the history of the commit the branch currently points to." and isn't ambiguous.

Re:Things I wish everyone knew about Git (Part I) by edflsafoiewq on Wednesday June 29, 2022 @06:35PM (#31926536)
I think it goes to all the parents, ie. a branch denote not a linear sequence of commits, but an entire sub-DAG.
Re:Things I wish everyone knew about Git (Part I) by lisper on Wednesday June 29, 2022 @03:05PM (#31924387)
> each commit points to their parent

Potentially more than one.

Re:Things I wish everyone knew about Git (Part I) by tomjakubowski on Wednesday June 29, 2022 @03:07PM (#31924415)
just to spell it out fully for dear reader: that's how merge commits work.
Re:Things I wish everyone knew about Git (Part I) by Anunayj on Wednesday June 29, 2022 @03:48PM (#31924889)
and Just for fun, sometimes it can be as big as 66, meet Cthulhu merge [1]

1. https://lkml.org/lkml/2014/1/21/361

Re:Things I wish everyone knew about Git (Part I) by chrismorgan on Thursday June 30, 2022 @12:50AM (#31928798)
There are realistic uses for more even than that. I’ve worked with a system of pre-production deploying where you labelled your PR/MR/whatever-you-call-it “include-in-beta” or whatever, and the beta branch would be reconstructed to be an octopus merge of the production branch and all include-in-beta heads. (When I came to the process, it was doing sequential merges, which got very slow when you had a whole bunch of work backing up that you couldn’t deploy to production just yet, so I turned it into a single octopus merge which was much, much faster, only falling back to sequential merges if the octopus merge failed, so that it could point out which MR conflicted. I don’t remember how high the numbers ever got, but I think it went beyond 66 at times, even with only a couple of dozen developers.)

Graph log visualisation was certainly fairly difficult to make much of, but it wasn’t generally intended to be made much of, since it was basically a deployment implementation detail.

Re:Things I wish everyone knew about Git (Part I) by wdfx on Wednesday June 29, 2022 @06:29PM (#31926475)
And when you are playing around with git to try this strategy and it's not allowed you get the wonderful error message "should not be doing an octopus".

(IIRC, from some version of git from about 6 years ago)

Re:Things I wish everyone knew about Git (Part I) by hinkley on Wednesday June 29, 2022 @04:26PM (#31925314)
Linus doesn't appear to be particularly enthusiastic about this strategy.

Humans really do handle treating changes as a sequence. I wonder if this was really necessary or could have been serialized.

Re:Things I wish everyone knew about Git (Part I) by HWR_14 on Wednesday June 29, 2022 @05:15PM (#31925817)
Mercurial, by the spec, only allows two parents to force merges like that into a sequence.
Re:Things I wish everyone knew about Git (Part I) by kjeetgill on Wednesday June 29, 2022 @08:07PM (#31927275)
I think bookmarks are a fine name but I don't really see quibble about branches, which I think are an even better name, but I know it's because I'm seeing it with my git goggles on.

Can you elaborate on what you think branches are a better reference to? What operations or concepts are better expressed in terms of them? I think I'm at the edge of an epiphany here ... but I'm not quite groking it yet.

Re:Things I wish everyone knew about Git (Part I) by emmelaich on Wednesday June 29, 2022 @10:22PM (#31928118)
The issue is the "named" bit of the definition, more precisely "named sequence".

A commit is as much a branch as a head of a linked list is both a node and a list.

I think 'branch' is fine.

Re:Things I wish everyone knew about Git (Part I) by kovac on Wednesday June 29, 2022 @10:34PM (#31928189)
Nice analogy there comparing it to a linked list.
Re:Things I wish everyone knew about Git (Part I) by omegalulw on Thursday June 30, 2022 @05:22AM (#31930266)
> a branch isn't a named sequence of commits, it's just a label that points to a single commit.

True, but in the past majority of cases parent commits in the branch (commits from leaf to the last ancestor that has only one child) would be semantically very related so this understanding is not that bad (so long as you remember a branch is a commit for git operations).

Re:Things I wish everyone knew about Git (Part I) by pdonis on Wednesday June 29, 2022 @07:27PM (#31927000)
> each commit points to their parent. Therefore, you don't need to track the entire sequence of commits in the branch but just the commit at the tip.

This is not entirely true, because it is perfectly possible to create commit graphs in git in which there is not a single well-defined branch for some commits. So just knowing the branch labels at each tip is not sufficient to assign a single well-defined branch to every commit in the graph.

Mercurial branches don't work like this: they are actually stored as part of each commit, so even with ambiguous commit graphs each commit still has a well-defined branch.

Re:Things I wish everyone knew about Git (Part I) by TacticalCoder on Wednesday June 29, 2022 @08:06PM (#31927267)
Yeah I much preferred Mercurial from that standpoint. And branches there were correctly named branch. But you kinda, sorta, can get "what should have been called branches but don't exist in Git" by using named tags when you "start a branch" (a real branch I mean, not a Git "branch").

> Mercurial branches don't work like this: they are actually stored as part of each commit, so even with ambiguous commit graphs each commit still has a well-defined branch.

I wonder which operation would not be possible with Git had Git gone that way. And hence I wonder too what's that operation that Git can do and that Mercurial can't.

Honestly switching from Mercurial to Git this weird "branch that aren't branch at all" was the single most WTF feature of Git.

Re:Things I wish everyone knew about Git (Part I) by shikoba on Thursday June 30, 2022 @05:40AM (#31930386)
> branch that aren't branch at all

What do you mean? Git branches are branches. What is a branch for you? And why git branches aren't?

Re:Things I wish everyone knew about Git (Part I) by pdonis on Thursday June 30, 2022 @01:04PM (#31935423)
Read the post of mine that TacticalCoder was responding to.
Re:Things I wish everyone knew about Git (Part I) by shikoba on Thursday June 30, 2022 @02:21PM (#31936420)
I already read it. It's not clear to me.