Git F**k It

Git Fuck It: Alias to delete all the stupid shit you did last night. Gets you back to a clean repository.

alias git-fuckit='git clean -d -x -f; git reset --hard'

Here’s how it works:

  • -d : Removes untracked directories
  • -x : Ignore rules in the .gitignore file
  • -f : Force it to happen
  • reset –hard : Discard any tracked files in the repository

Late night hacking goes like thisUsually around 1am I’ll get some bat-shit-crazy idea. Something like, “This class sucks. I should rewrite the whole thing!” So I start hacking at it.

I slaughter everything! Tests? Documentation? Forget it. Nothing is safe. By the time I’m done it’s 3am, I’m completely exhausted, delirious, and I’ve managed to touch every file in the repository. That’s when I close my laptop and go to sleep.

When I wake up the next morning, I’ll look at this complete train wreck I made and go, “Oh. My. God. What have I done?” Everything is broken! Tests are failing, Rails won’t start, and none of it makes any sense.

So I made “git fuck it.” It erases everything I did and gets back to the last good commit. It’s inelegant and unforgiving but it cures all the coding sins from the night before. The code is made whole again.

6 thoughts on “Git F**k It

  1. In situations like this i use:
    git stash

    • I could totally use Git stash, except I don’t want to keep any of it. I actually want to get rid of it entirely. Thanks!

  2. You could also set this as a git alias, rather than a shell alias:

    > git config –global alias.fuckit ‘!git clean -d -x -f && git reset –hard’

    $ git fuckit
    HEAD is now at 8343e45 Pointless commit to test swearing online

  3. My “fuckit” alias is just “rebase –abort”.

  4. Alternatively you could have done it all in a branch – and delete the branch, (having enjoyed the benefits of having committed stuff, and other version control goodness, as you went along).

Leave a Reply

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