I’ve read the similar posts on this topic, and can’t for the life of me figure out how to do this properly.
I checked in about 1000 files that I don’t want, and I’d rather not have to go through 1by1 and remove them all from the repo.
- I have a remote
masterBranch. - I have the local
masterBranch.
They are both at the same revision.
I want to rollback my remote by 1 commit.
Say my history on master is A--B--C--D--E.
I want to rollback my local to D.
Then push it to remote so my current hash will be D both remote and local.
I’m having issues doing this.
I’m using Git Tower but am comfortable with the command line. Any help?
UPDATE:
Great comments below. Using a reset seems to be partially discouraged especially if the repository is shared with other users.
What’s the best way to undo the previous commit’s changes without using a hard reset? Is there a way?
If nobody has pulled your remote repo yet, you can change your branch HEAD and force push it to said remote repo:
(or, if you have direct access to the remote repo, you can change its HEAD reference even though it is a bare repo)
Note, as commented by alien-technology in the comments below, on Windows (CMD session), you would need
^^:And? as noted in the comments by Jon Schneider:
Update since 2011:
Using
git push --force-with-lease(that I present here, introduced in 2013 with Git 1.8.5) is safer.See Schwern‘s answer for illustration.
Then I would suggest something that doesn’t rewrite the history:
git revertlocally your last commit (creating a new commit that reverses what the previous commit did)git revert.