How to fix that mistake commit you just pushed to your git repository

I've already written a time or two how you can use git rebase to change your commit history as you work. Handy handy.. I think everyone should know how to do that.

Next up.. what if you pushed a commit and realize it's not so great. First of all, everyone discourages this of course. The encouraged way is to just make another commit that fixes what you want different. We all want to break that rule every now and then though. Here's how...

1) Fix your current branch (usually master).
Use the commit --amend or rebase to make it the way you want.
2) Remove the remote master

  1.  
  2. > git push origin :master
  3.  

3) Push your rewritten master back to origin.

  1.  
  2. > git push origin master
  3.  

OK, newer versions of git deny deleting the current branch. Just set a property to allow that first then you're good to go.

  1.  
  2. > #ssh/cd or whatever to origin repository
  3. > git config receive.denyDeleteCurrent ignore
  4.  

Lastly, what if someone actually pulled your changes after you pushed them? They just need to reset to an earlier commit and pull again

  1.  
  2. > git reset --hard HEAD^ # or whatever sha or previous revision that was common.
  3. > git pull # gets the latest version with the corrected commit now.
  4.  

Have fun.

  1. No Comments



css.php