Live data from Hacker News

Oh Shit, Git?

ohshitgit.com

231–240 of 275 posts

Re: Oh Shit, Git?

#231
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…

> is there a command that simply moves a branch from one commit to another without changing anything else? It feels like it should be possible given how git works.

git switch -C master HEAD~

Re: Oh Shit, Git?

#232
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…

> 2. Avoid `reset --hard` at all costs

Sounds like you might be looking for `git reset --keep`

Re: Oh Shit, Git?

#233

Silly comment, but: Every time I see `git reflog`, I see it as re-flog. It's possible that's even the reason I never remember the command, I subconsciously can't bring myself to think of it as "reference log". Instead, it's asking git to sell something cheaply, again .

I have that with fstab

Re: Oh Shit, Git?

#234
post #164

We should start recommending UIs as the default way to learn Git. It would solve a third of these problems and another third wouldn't even come up. If you later decide that the CLI is faster, go ahead. But first, people need to see visually how they can interact with the tree. I like fork.dev, but most clients are pretty similar at this point.

> But first, people need to see visually how they can interact with the tree. Interactive tutorial with tree visualization that has helped co-workers: https://learngitbranching.js.org/

Thank you for posting that!

Re: Oh Shit, Git?

#235

Earlier quoted context omitted.

None of these seem to preclude a command to make an arbitrary branch point to an arbitrary commit without changing anything else.

You are looking for git update-ref

Wouldn't the fail or break under any circumstance where they don't immediately share a history?

Re: Oh Shit, Git?

#236
post #14

Earlier quoted context omitted.

> 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.

That's, for secrets. Secrets aren't the only thing one might want to remove retroactively.

Re: Oh Shit, Git?

#238
post #81

Earlier quoted context omitted.

This should be a built-in git unshit Or git add --unshit -f ~HEAD^^ If you’re using git version <= 2.844.

Jujutsu has `jj undo`, but which undoes whatever was your last jj command, regardless of what it was. It makes much more confident to do an operation I'm uncertain of. And if I regret something many actions down the line, you have `jj op log` (a better reflog).

Such a simple operation, but it'd probably fix 95% of problems I've had with git.

"Uh oh, I tried to checkout a branch from remote by doing `git checkout origin/some-branch` instead of `git checkout some-branch` and made a couple source changes. Now I'm in detached head state. What is detached head ? I have to stash my revisions? Can I make a new branch with the same name or do I need to delete the origin/some-branch that I'm on?"

When you could be able to just revert the "operation" and check out the correct branch, that's amazing.

Re: Oh Shit, Git?

#239
post #232
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…

> 2. Avoid `reset --hard` at all costs Sounds like you might be looking for `git reset --keep`

[deleted]

Re: Oh Shit, Git?

#240

Before learning magit on emacs, this site saved my ass so many times. After learning magit on emacs, this site saved my ass so many times.

It used to save my ass a lot. It still does, but it used to, too.
Post reply on HN