tags:

views:

63

answers:

2

Hello,

I committed and pushed some bad things. How do I force revert my local repo to HEAD~7, and re-commit so that HEAD is now at that version? Git docs confuse me.

Thanks!

+8  A: 

The nicest approach is to push another commit that reverts the unintended commits. See Jakub Narębski's answer on how to do that.

If for some reason it's worth the potential unfriendliness of pushing an update that isn't a fast-forward (sensitive bits in the commits, for example), give these commands:

git reset --hard HEAD~7
git push --force origin master

The first rewinds your current branch. This is a sharp tool, so be careful.

To stop you accidentally losing work, git won't push your rewound branch. The --force option disables this safety feature.

Greg Bacon
+2  A: 

git reset --hard HEAD~7 will discard your changes entirely.

git reset HEAD~7 will drop the commits but leave changes in the working copy, so that you can edit and re-commit them.

Roman Cheplyaka