Live data from Hacker News

Oh Shit, Git?

ohshitgit.com

31–40 of 275 posts

Re: Oh Shit, Git?

#31
post #3

Some changes I would make: 1. Always use `git switch` instead of `git checkout` 2. Avoid `reset --hard` at all costs. So for the "accidentally committed something to master that should have been on a brand new branch" issue, I would do this instead: # create a new branch from the current state of master git branch some-new-branch-name # switch to the previous commit git switch -d HEAD~ # overwrite master branch to th…

What's the problem with `reset --hard`?

Re: Oh Shit, Git?

#32
post #30

Earlier quoted context omitted.

I guess we're coming from different places. In my vernacular, ending a comment with "...really?" is about as casual as calling somebody bro. It's gender neutral btw.

"Bro" is the furthest thing from "gender neutral". Not sure how you could think it's gender neutral. It originated from male behavior and is definitely not gender neutral. You can address women as "bro" and they might even respond to you but they'll think you're absolutely weird.

"bro", "bruh", it's more of an exclamation of surprise than a title conferred to the person being addressed, but even then, I don't know, people call folks "auntie" and "uncle" who aren't actually their auntie and uncle. language is flexible. it may reference the kind of fraternity between brothers but that feeling is not limited to the male sex.

Re: Oh Shit, Git?

#33
post #3

Some changes I would make: 1. Always use `git switch` instead of `git checkout` 2. Avoid `reset --hard` at all costs. So for the "accidentally committed something to master that should have been on a brand new branch" issue, I would do this instead: # create a new branch from the current state of master git branch some-new-branch-name # switch to the previous commit git switch -d HEAD~ # overwrite master branch to th…

The disconnect between git's beautiful internal model of blobs, a tree of commits, and pointers to commits, and the command line interface is so wild. All of these recipes are unintuitive even if you have a firm grasp of git's model; you also need to know the quirks of the commands! To just look at the first one... wouldn't it be more intuitive for the command line interface to be: # this command exists already; $ gi…

I prefer just using `git switch` because it's easy to remember the flags (and the position of arguments), but you're right, there is a simpler way:

    git switch -c some-new-branch-name
    git branch -f master HEAD~

Re: Oh Shit, Git?

#34
post #4

Git is one of those technologies that I never got to wrap my head around of, because in so many ways it doesn't follow intuition and unless you have been using it for a long time, for literally every action you would probably have to Google or use the man page of the command.

As everyone knows, though, Git gets easier once you understand branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space.

Re: Oh Shit, Git?

#35
post #3

Some changes I would make: 1. Always use `git switch` instead of `git checkout` 2. Avoid `reset --hard` at all costs. So for the "accidentally committed something to master that should have been on a brand new branch" issue, I would do this instead: # create a new branch from the current state of master git branch some-new-branch-name # switch to the previous commit git switch -d HEAD~ # overwrite master branch to th…

The disconnect between git's beautiful internal model of blobs, a tree of commits, and pointers to commits, and the command line interface is so wild. All of these recipes are unintuitive even if you have a firm grasp of git's model; you also need to know the quirks of the commands! To just look at the first one... wouldn't it be more intuitive for the command line interface to be: # this command exists already; $ gi…

The "move a branch from one commit to another without changing anything" command is "git reset".

"git reset --hard" is "...and also change all the files in the working directory to match the new branch commit".

"git reset --soft" is "...but leave the working directory alone".

Re: Oh Shit, Git?

#36
post #3

Some changes I would make: 1. Always use `git switch` instead of `git checkout` 2. Avoid `reset --hard` at all costs. So for the "accidentally committed something to master that should have been on a brand new branch" issue, I would do this instead: # create a new branch from the current state of master git branch some-new-branch-name # switch to the previous commit git switch -d HEAD~ # overwrite master branch to th…

What's the problem with `reset --hard`?

It leaves behind tracked files that were moved or deleted between revisions.

Re: Oh Shit, Git?

#37

Earlier quoted context omitted.

Bro, really, self-taught people with a bare minimum understanding of the tools they use are super normal, and when they get into a pit they have to fix it themselves. Although to your point folks would be better served carefully reading the docs / git book than googling a specific solution to their specific error code.

[flagged]

U r

Re: Oh Shit, Git?

#38
I'm not a git user, but stuff like this really drives home the idea that "git commit" is meaningless, the only thing that matters is when your commits are pushed or merged.

It's like saving a textfile. Do you write a little message every time you save a file? No that's silly. Just move on.

Re: Oh Shit, Git?

#39
post #14

Earlier quoted context omitted.

Possibly consider that "deleting a file from history" is rather far outside the norm or recommended practice for git (even though it is, of course, entirely possible)

> even though it is, of course, entirely possible I take the more realistic perspective: until git makes it impossible to commit something that shouldn't have been, like a secret, then deleting a file from history is a fundamental requirement of git.

Even if you purge the history, the secret is compromised and you should stop using it. It's moot whether or not you're able to remove it from history.

Re: Oh Shit, Git?

#40

I'm not a git user, but stuff like this really drives home the idea that "git commit" is meaningless, the only thing that matters is when your commits are pushed or merged. It's like saving a textfile. Do you write a little message every time you save a file? No that's silly. Just move on.

If I'm saving changes that were done because of a arduous debugging journey and other people are likely to have to refer back to it, yes. In fact, forget little; the smaller the change is, the bigger the text. Some of my changes have 2-3 paragraphs for a 2-3 line change because of the impact.
Post reply on HN