News for hackers. Stuff that matters.
Re:Some bad Git situations and how I got myself out of them by random567 on Friday September 09, 2016 @02:00AM (#12459912)
The screwed up and committed to master should end with:

     git reset --hard origin/master
(assuming that the remote is called "origin") With the example in the text, you have to know the number of commits you've made to master.
Re:Some bad Git situations and how I got myself out of them by NickHolt on Friday September 09, 2016 @02:11AM (#12459952)
It was also a bit pointless to checkout a new branch just to switch back. The whole thing should be

    git branch some-new-branch-name
    git reset --hard origin/master
    git checkout some-new-branch-name
Re:Some bad Git situations and how I got myself out of them by NickHolt on Friday September 09, 2016 @02:16AM (#12459978)
The "committed to wrong branch" case is also a little overly complex. I'd just do:

    git checkout correct-branch
    git cherry-pick wrong-branch
    git checkout wrong-branch
    git reset --hard HEAD~
Re:Some bad Git situations and how I got myself out of them by Dru89 on Friday September 09, 2016 @02:57AM (#12460123)
This is less safe than the branching alternatives. Instead of "moving" the original commit, this copies the original commit to a new one and leaves the original one dangling and waiting to be garbage collected.

Also, if you have more than one commit before you noticed you were on the wrong branch, this only grabs the one commit.

Re:Some bad Git situations and how I got myself out of them by ekimekim on Friday September 09, 2016 @04:33AM (#12460465)
tip: you can use @{u} to refer to "the upstream of my current branch", ie. what you said but will work no matter what the remote is called.
Re:Some bad Git situations and how I got myself out of them by swang on Friday September 09, 2016 @02:23AM (#12460004)
the website's example is for when you only want to undo just the last commit you made.