1

New to git, this should be very simple, but I from some reason I am unable to do it. I made changes to a file, I staged and committed it locally. I then pushed the changes to my remote git server, I now want to revert these changes on the remote server ?

How do I do that ?

Pacman
  • 2,183
  • 6
  • 39
  • 70

1 Answers1

2

Two ways:

  • create a revert commit, and push it. This will have the story look like this:

    good commit -> faulty commit -> reverse of the faulty commit 
    
    git revert <faultycommitSHA>
    git push
    
  • rewrite the story, makes the faulty commit as if it never existed

    git reset <goodcommitSHA>
    

If you pushed the bad commit to a server, though, you can't rewrite the story on the server, BUT if you are ABSOLUTELY SURE that there are no other copies of the faulty around you can REMOVE the branch from the server, and push it again. I'll repeat the warning because it is important: DON'T DO IF YOU OR OTHER CONTRIBUTORS PULLED THE FAULTY COMMIT SOMEWHERE ELSE, because you will have conflicts which will merge back the faulty commit into the main branch.

git push origin :branchname # deletes the branch on the origin remote
git push origin branchname  # pushes the branch on the origin remote

You can remove the old branch in whatever way you are allowed - for example by using the web interface on GitHub

pqnet
  • 6,070
  • 1
  • 30
  • 51
  • You would actually need to hard reset, not just a normal reset, unless you clean up the working copy after doing it. A hard reset will take care of that for you already though. Also, please don't use ALL CAPS for **emphasis**. –  Aug 09 '14 at 03:37