Set older revision to be the HEAD, revert to previous state with “git push”, undo remote historyBy neokrates, written on July 15, 2010
You have some status in the repository which you want “HEAD” to point to. With Git remote HEAD can be set by forcing the push command.
Such method is useful for example if you want rollback or undo your commits until some particular revision. After you done, master revision is altered.
History in the remote repository is erased as well as changes until the new HEAD revision. Anyone who makes a new clone will get the ‘new’ HEAD you just set.
If you or someone else pushes the ‘OLD’ repository state, the history will be restored. Pushing changes from the clone made after
git push -f origin works OK and creates new ‘commit history’ from the point you set.
List avalable revisions
# git rev-list HEAD 70c5717dce2e023943cc4168dc95632a5baee6af bc84dc5eb220a471c9a5a932fe7ef2e4501320be fa1504a9e5b0d1e0ee6064a9b80c838dc81a8ef9 442448e186a03db5f5470ca438e69b2ee2a67f71 4b9bfe2dd388d34ba5ba4400990e69744af44fd2 6c138222515306009c35303e9a4653573875b992 daae8a1798c8d66bbe1738d177ed9075abaa94d6 5b96cb0d40b1f55a935f5c74970b72421fef6d00 e08918323e03800468e1d8de8d813ac2c1383408
Set new HEAD
# git push -f origin 5b96cb0d40b1f55a935f5c74970b72421fef6d00:master Total 0 (delta 0), reused 0 (delta 0) => Syncing Gitorious... [OK] To email@example.com:your-project/your-repo.git + daae8a1...5b96cb0 5b96cb0 -> master (forced update)
And for any other branch
git checkout your-branch git rev-list your-branch // select your rev, i.e. SHA1 = 4b9bfe2dd388 git push -f origin 4b9bfe2dd388:your-branch