News for hackers. Stuff that matters.
Re:Google has sent internet into 'spiral of decline', claims... by kmlx on Sunday October 15, 2023 @05:21AM (#37888263)
> when you search for something like "how to reverse a pushed commit in git"

i use chatgpt for those kinds of questions. i don't have time to read an article or select a non-spam site or even look at the stack overflow answer.

Re:Google has sent internet into 'spiral of decline', claims... by moritzwarhier on Sunday October 15, 2023 @05:58AM (#37888448)
So I understood you want to reverse a pushed commit on both your local repository and the remote. You can reverse that commit using just the following commands:

  git reset --hard HEAD~2
  git reflog expire --expire-unreachable=now
  git push -f
This reverses the most recent commit. The -f is needed to reverse the commit on your git server.

...

I apologize if my previous response wasn't helpful. I see that you meant "revert" and not "reverse". I apologize that two of your commits are now gone and I understand that you mean "revert", not "reverse"? You could try

  git revert HEAD
  git push
If you have any more questions, I'll be glad to help. :)

Maybe I'm underestimating GPT-4 here, but when I tried to get it to write my some CLI commands, it failed in often non-obvious ways (I was trying to resize and compress an image using imagemagick).

Seemed like a waste of time to try&error with the responses, compared to looking up the documentation.

But well, man yelling at cloud I guess.

For programming and computer questions, I'm still grateful for StackOverflow and its sister sites. Finding a conprehensive answer with lots of updates and comments describing different aspects of the problem, all for exactly the question I asked, is satisfying and it feels very time-efficient too.

Re:Google has sent internet into 'spiral of decline', claims... by Am4TIfIsER0ppos on Sunday October 15, 2023 @07:37AM (#37888915)
> git reset --hard HEAD~2

Stupid computer. That does 2 commits.

> git reflog expire --expire-unreachable=now

For the love of god why? The reflog is there to save your bacon. I guess because they are still reachable from the remote's reference so they won't completely vanish just yet.

> git push -f

Now they're gone unless you can find the hashes somewhere else. The objects might still be present.

> I apologize that two of your commits are now gone

Is that you or still GPT?

Re:Google has sent internet into 'spiral of decline', claims... by EForEndeavour on Sunday October 15, 2023 @08:12AM (#37889104)
Nah, they likely didn't bother trying to ask GPT-4 and imagined hypothetical answers which could lead beginners to shoot themselves in the foot.

ChatGPT Plus with a short custom instruction to answer in steps, respond tersely, ask clarifying questions where needed, and make recommendations wherever possible replied to "how to reverse a pushed commit in git" with:

---

To reverse a pushed commit in Git, you can either use git revert or git reset. Each approach has pros and cons.

# Option 1: git revert

Pros: Safe for shared branches, creates a new commit to undo changes.

Cons: Adds noise to history.

Commands:

    git revert [COMMIT_HASH]

    git push origin [BRANCH_NAME]
# Option 2: git reset

## Soft Reset

Pros: Keeps changes in your working directory.

Cons: Rewrites history; risky for shared branches.

Commands:

    git reset --soft [COMMIT_HASH]^

    git commit -m "Reverting previous commit"

    git push origin [BRANCH_NAME] --force-with-lease
## Hard Reset

Pros: Completely removes commit.

Cons: Rewrites history; risky for shared branches; discards changes.

Commands:

    git reset --hard [COMMIT_HASH]^

    git push origin [BRANCH_NAME] --force-with-lease
Recommendation:

Use git revert for shared branches to avoid conflicts. Use git reset for local or feature branches where you control all changes. Clarify your specific scenario for a tailored recommendation.

Re:Google has sent internet into 'spiral of decline', claims... by moritzwarhier on Sunday October 15, 2023 @08:37AM (#37889248)
You are correct! I was fantasizing how a bad GPT answer could look like, similar to the errors that were in the answers to my prompts to GPT-3.5 for imagemagick. These prompts where precise and in good faith, with some rounds of clarification.

I am sure newer GPT versions will do better, and I think for a tool as ubiquitous as git the answers from ChatGPT would have been perfectly fine too.

Just wanted to illustrate why I wouldn't mske it a habit to ask it factual questions.

The "lost two commits" answer was meant as whimsy joke. More realstic scenarios are more boring of course.

E.g. memorizing wrong explanations for solitions that happen to work, or accepting wrong answers as fact when it's inconsequential for the short term acceptance of the answer.

Re:Google has sent internet into 'spiral of decline', claims... by morning-coffee on Sunday October 15, 2023 @10:52AM (#37890260)
C:\> debug g=c800:5
Re:Google has sent internet into 'spiral of decline', claims... by Am4TIfIsER0ppos on Sunday October 15, 2023 @09:33AM (#37889575)
Okay the previous wasn't real GPT but this is?

> git reset --soft [COMMIT_HASH]^

The docs say files are unchanged.

> git reset --soft [COMMIT_HASH]^

Committing the unchanged files so like an amend, a squash, not exactly reversing, reverting, or undoing anything except commit messages.

Re:Google has sent internet into 'spiral of decline', claims... by moritzwarhier on Sunday October 15, 2023 @08:51AM (#37889328)
None of this was GPT and thankfully I know what the git commands I used in my not-so-great joke answer do.

As replied in the sister thread, I think that the risks of trusting GPT answers can be more subtle.

Re:Google has sent internet into 'spiral of decline', claims... by darkerside on Sunday October 15, 2023 @09:41AM (#37889643)
I'm torn because the joke was technically spreading FUD but I also found it very funny. ...upvoted