Technology

Git, Damn You

I’m always committing to the wrong branch, then I have to google rollback commit which gets me to a solution like this (see SO here):

$ git commit -m "Something terribly misguided" # (0: Your Accident)
$ git reset HEAD~                              # (1)
<< edit files as necessary >>                  # (2)
$ git add .                                    # (3)
$ git commit -c ORIG_HEAD                      # (4)

This is fine and all, but clobbers the original commit. Now I’m six commits in and realize I’m on the wrong branch for fuck’s sake. So thinking this through, I can create a branch based on my current HEAD, then reset the original branch. Something like this:

git branch feature/intial-commit
git checkout master
git reset --hard origin/master

I’ll continue to add idiocy here.

Leave a Reply

Your email address will not be published. Required fields are marked *